ソースを参照

旋转不销毁生命周期

詹子聪 5 年 前
コミット
db3dfc4822

+ 2 - 1
app/src/main/AndroidManifest.xml

@@ -9,7 +9,8 @@
         android:roundIcon="@mipmap/ic_launcher_round"
         android:supportsRtl="true"
         android:theme="@style/AppTheme">
-        <activity android:name=".MainActivity">
+        <activity android:name=".MainActivity"
+            android:configChanges="orientation|screenSize|keyboardHidden">
             <intent-filter>
                 <action android:name="android.intent.action.MAIN" />
 

+ 3 - 1
mvp/src/main/java/com/miekir/mvp/presenter/BasePresenter.java

@@ -1,5 +1,7 @@
 package com.miekir.mvp.presenter;
 
+import android.os.Looper;
+
 import androidx.lifecycle.ViewModel;
 
 import com.miekir.common.utils.LogTool;
@@ -33,7 +35,7 @@ public abstract class BasePresenter<V extends IView> extends ViewModel {
     public V getCallbackView() {
         mViewHandler.setView(getView());
         return  (V) Proxy.newProxyInstance(
-                Thread.currentThread().getContextClassLoader(),
+                Looper.getMainLooper().getThread().getContextClassLoader(),
                 mViewHandler.getClazz().getInterfaces(),
                 mViewHandler);
     }