问题
I have an application in which i got tablayout with two fragments, the app works perfectly fine but when i close app using menu button and use other apps for a while and when i resume my app it crashes with the following exception
FATAL EXCEPTION: main Process: com.example.com, PID: 5674 java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.com/com.example.ui.activity.MainActivity}: java.lang.RuntimeException: Parcel android.os.Parcel@9095b3a: Unmarshalling unknown type code 3801188 at offset 4392 at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2426) at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2490) at android.app.ActivityThread.-wrap11(ActivityThread.java) at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1354) at android.os.Handler.dispatchMessage(Handler.java:102) at android.os.Looper.loop(Looper.java:148) at android.app.ActivityThread.main(ActivityThread.java:5443) at java.lang.reflect.Method.invoke(Native Method) at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:728) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:618) Caused by: java.lang.RuntimeException: Parcel android.os.Parcel@9095b3a: Unmarshalling unknown type code 3801188 at offset 4392 at android.os.Parcel.readValue(Parcel.java:2340) at android.os.Parcel.readArrayMapInternal(Parcel.java:2614) at android.os.BaseBundle.unparcel(BaseBundle.java:221) at android.os.Bundle.getSparseParcelableArray(Bundle.java:856) at com.android.internal.policy.PhoneWindow.restoreHierarchyState(PhoneWindow.java:2033) at android.app.Activity.onRestoreInstanceState(Activity.java:1008) at android.app.Activity.performRestoreInstanceState(Activity.java:963) at android.app.Instrumentation.callActivityOnRestoreInstanceState(Instrumentation.java:1186) at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2399) at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2490) at android.app.ActivityThread.-wrap11(ActivityThread.java) at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1354) at android.os.Handler.dispatchMessage(Handler.java:102) at android.os.Looper.loop(Looper.java:148) at android.app.ActivityThread.main(ActivityThread.java:5443) at java.lang.reflect.Method.invoke(Native Method) at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:728) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:618)
i tried disabling the proguard and adding below code but nothing helps
-keepclassmembers class * implements android.os.Parcelable { static ** CREATOR; }
i have custom view but haven't implemented parcelable in them also i have striped everything from fragment and just kept the view even then it was crashing but when i was just loading instance of fragment like new android.support.v4.app.Fragment(); i wasn't getting the error
回答1:
I faced the same issue and found the solution to start the app again to stop the crash
In your MainActivity
Use:
@Override
protected void onRestoreInstanceState(Bundle savedInstanceState) {
try {
super.onRestoreInstanceState(savedInstanceState);
}catch (Exception e){
e.printStackTrace();
Intent intent=new Intent(this,MainActivity.class);
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
intent.addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP);
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(intent);
}
}
回答2:
This was due to a bug in SearchView since appcompat v23.2.0.
It is fixed in v23.2.1. Upgrade your support libraries to get rid of the exception.
来源:https://stackoverflow.com/questions/35897517/unmarshalling-unknown-type-code-exception-while-resuming