У меня есть мероприятие и ведущий, у которого нет конструктора по умолчанию, введенное с помощью koin:
class HomeActivityPresenter<V : HomeActivityNav>(dataManager: DataManager, schedulerProvider: SchedulerProvider) :
BaseViewModel<V>(dataManager, schedulerProvider) HomeActivityListener, Serializable {
В упражнении я надуваю фрагмент с помощью метода addFragment
:
fun AppCompatActivity.addFragment(fragment: Fragment, frameId: Int) {
supportFragmentManager.inTransaction { add(frameId, fragment) }
}
Я тестирую свое приложение с Don't keep activities
. Пока занятие открыто, я нажимаю кнопку «Домой», чтобы перевести приложение в фоновый режим. Когда активность восстановлена, я получил этот cra sh:
java.lang.RuntimeException: Unable to start activity ComponentInfopackagename.ui.features.home.activity.HomeActivity}: java.lang.RuntimeException: Parcelable encountered IOException reading a Serializable object (name = packagename.ui.features.home.activity.HomeActivityPresenter)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3270)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3409)
at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:83)
at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:135)
at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:95)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2016)
at android.os.Handler.dispatchMessage(Handler.java:107)
at android.os.Looper.loop(Looper.java:214)
at android.app.ActivityThread.main(ActivityThread.java:7356)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:492)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:930)
Caused by: java.lang.RuntimeException: Parcelable encountered IOException reading a Serializable object (name = packagename.ui.features.home.activity.HomeActivityPresenter)
at android.os.Parcel.readSerializable(Parcel.java:3136)
at android.os.Parcel.readValue(Parcel.java:2917)
at android.os.Parcel.readArrayMapInternal(Parcel.java:3244)
at android.os.BaseBundle.initializeFromParcelLocked(BaseBundle.java:292)
at android.os.BaseBundle.unparcel(BaseBundle.java:236)
at android.os.BaseBundle.getString(BaseBundle.java:1160)
at android.os.BaseBundle.getString(BaseBundle.java:1182)
at packagename.ui.features.orderstatus.PickupOrderStatusDetailFragment.onCreate(PickupOrderStatusDetailFragment.kt:49)
at androidx.fragment.app.Fragment.performCreate(Fragment.java:2586)
at androidx.fragment.app.FragmentManagerImpl.moveToState(FragmentManagerImpl.java:838)
at androidx.fragment.app.FragmentManagerImpl.moveFragmentToExpectedState(FragmentManagerImpl.java:1238)
at androidx.fragment.app.FragmentManagerImpl.moveToState(FragmentManagerImpl.java:1303)
at androidx.fragment.app.FragmentManagerImpl.dispatchStateChange(FragmentManagerImpl.java:2659)
at androidx.fragment.app.FragmentManagerImpl.dispatchCreate(FragmentManagerImpl.java:2607)
at androidx.fragment.app.FragmentController.dispatchCreate(FragmentController.java:235)
at androidx.fragment.app.FragmentActivity.onCreate(FragmentActivity.java:316)
at androidx.appcompat.app.AppCompatActivity.onCreate(AppCompatActivity.java:106)
at packagename.features.home.activity.HomeActivity.onCreate(HomeActivity.kt:84)
at android.app.Activity.performCreate(Activity.java:7802)
at android.app.Activity.performCreate(Activity.java:7791)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1299)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3245)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3409)
at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:83)
at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:135)
at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:95)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2016)
at android.os.Handler.dispatchMessage(Handler.java:107)
at android.os.Looper.loop(Looper.java:214)
at android.app.ActivityThread.main(ActivityThread.java:7356)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:492)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:930)
Caused by: java.io.InvalidClassException: packagename.ui.features.home.activity.HomeActivityPresenter; no valid constructor
at java.io.ObjectStreamClass$ExceptionInfo.newInvalidClassException(ObjectStreamClass.java:154)
at java.io.ObjectStreamClass.checkDeserialize(ObjectStreamClass.java:798)
at java.io.ObjectInputStream.readOrdinaryObject(ObjectInputStream.java:1873)
at java.io.ObjectInputStream.readObject0(ObjectInputStream.java:1412)
at java.io.ObjectInputStream.readObject(ObjectInputStream.java:427)
at android.os.Parcel.readSerializable(Parcel.java:3134)
at android.os.Parcel.readValue(Parcel.java:2917)
at android.os.Parcel.readArrayMapInternal(Parcel.java:3244)
at android.os.BaseBundle.initializeFromParcelLocked(BaseBundle.java:292)
at android.os.BaseBundle.unparcel(BaseBundle.java:236)
at android.os.BaseBundle.getString(BaseBundle.java:1160)
at android.os.BaseBundle.getString(BaseBundle.java:1182)
at packagename.ui.features.orderstatus.PickupOrderStatusDetailFragment.onCreate(PickupOrderStatusDetailFragment.kt:49)
at androidx.fragment.app.Fragment.performCreate(Fragment.java:2586)
at androidx.fragment.app.FragmentManagerImpl.moveToState(FragmentManagerImpl.java:838)
at androidx.fragment.app.FragmentManagerImpl.moveFragmentToExpectedState(FragmentManagerImpl.java:1238)
at androidx.fragment.app.FragmentManagerImpl.moveToState(FragmentManagerImpl.java:1303)
at androidx.fragment.app.FragmentManagerImpl.dispatchStateChange(FragmentManagerImpl.java:2659)
at androidx.fragment.app.FragmentManagerImpl.dispatchCreate(FragmentManagerImpl.java:2607)
at androidx.fragment.app.FragmentController.dispatchCreate(FragmentController.java:235)
at androidx.fragment.app.FragmentActivity.onCreate(FragmentActivity.java:316)
at androidx.appcompat.app.AppCompatActivity.onCreate(AppCompatActivity.java:106)
at packagename.ui.features.home.activity.HomeActivity.onCreate(HomeActivity.kt:84)
at android.app.Activity.performCreate(Activity.java:7802)
at android.app.Activity.performCreate(Activity.java:7791)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1299)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3245)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3409)
at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:83)
at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:135)
at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:95)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2016)
at android.os.Handler.dispatchMessage(Handler.java:107)
at android.os.Looper.loop(Looper.java:214)
at android.app.ActivityThread.main(ActivityThread.java:7356)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:492)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:930)
Это строка 49 моего фрагмента, на которую указывает мой cra sh:
val orderStatus = args.getString(Constants.pickUpOrderCreate, "")
Я надеваю не знаю, как это исправить.