问题
I am working on Shared elements Transitions in Android and have executed the animations perfectly. The problem I am facing is when passing data using Intents. So, I basically start Intent from ActivityA, which is the first screen containing a recycler view, do an ImageTransform using TransitionName and start ActivityB, which contains a details activity containing a ViewPager. Now, when I press back button, ActivityB calls finishAfterTransition in which I create an Intent and set the result as follows:
@Override
public void finishAfterTransition() {
Intent data=new Intent();
data.putExtra("Student", new Student("id", "name", "grade"));
data.putExtra("CURRENT_POSITION", 2);
data.putExtra("LAST_POSITION", 5);
setResult(ProfileConstant.ResponseCode.COMPLETE_PROFILE, data);
finishAfterTransition = true;
super.finishAfterTransition();
}
Student Model is the same as answered at this link. In ActivityA, I am using
public void onActivityReenter(int resultCode, Intent data) {
Student sr = (Student) bundle.getParcelable("Student");
current_position = bundle.getInt("CURRENT_POSITION", -1);
int last_position = bundle.getInt("LAST_POSITION", -1);
}
which throws the following exception.
All the Animations works completely fine, when I dont pass the Student Object and everything works as intended, without throwing any exception. I am also using setEnterSharedElementCallback and setExitSharedElementCallback for mapping the views and their transition name, which has nothing to do with the Intent.
I don't understand why passing a parcelable object in Intent does not work with Transitions. Is there a workaround or am I doing it the wrong way? Would appreciate suggestions. I have presented only relevent code here.
Class not found when unmarshalling: mypackage.parcelable_object.Student
java.lang.ClassNotFoundException: myPackage.parcelable_object.Student
at java.lang.Class.classForName(Native Method)
at java.lang.Class.forName(Class.java:309)
at java.lang.Class.forName(Class.java:273)
at android.os.Parcel.readParcelableCreator(Parcel.java:2281)
at android.os.Parcel.readParcelable(Parcel.java:2245)
at android.os.Parcel.readValue(Parcel.java:2152)
at android.os.Parcel.readArrayMapInternal(Parcel.java:2485)
at android.os.BaseBundle.unparcel(BaseBundle.java:221)
at android.os.Bundle.getParcelable(Bundle.java:755)
at myPackage.MainActivity.onActivityReenter(MainActivity.java:211)
at android.app.ActivityTransitionState.setEnterActivityOptions(ActivityTransitionState.java:164)
at android.app.Activity.performStart(Activity.java:6002)
at android.app.Activity.performRestart(Activity.java:6063)
at android.app.ActivityThread.handleWindowVisibility(ActivityThread.java:3473)
at android.app.ActivityThread.access$1200(ActivityThread.java:151)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1337)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:135)
at android.app.ActivityThread.main(ActivityThread.java:5254)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:903)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:698)
Caused by: java.lang.ClassNotFoundException: Didn't find class "myPackage.parcelable_object.Student" on path: DexPathList[[directory "."],nativeLibraryDirectories=[/vendor/lib, /system/lib]]
at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:56)
at java.lang.ClassLoader.loadClass(ClassLoader.java:511)
at java.lang.ClassLoader.loadClass(ClassLoader.java:469)
at java.lang.Class.classForName(Native Method)
at java.lang.Class.forName(Class.java:309)
at java.lang.Class.forName(Class.java:273)
at android.os.Parcel.readParcelableCreator(Parcel.java:2281)
at android.os.Parcel.readParcelable(Parcel.java:2245)
at android.os.Parcel.readValue(Parcel.java:2152)
at android.os.Parcel.readArrayMapInternal(Parcel.java:2485)
at android.os.BaseBundle.unparcel(BaseBundle.java:221)
at android.os.Bundle.getParcelable(Bundle.java:755)
at myPackage.MainActivity.onActivityReenter(MainActivity.java:211)
at android.app.ActivityTransitionState.setEnterActivityOptions(ActivityTransitionState.java:164)
at android.app.Activity.performStart(Activity.java:6002)
at android.app.Activity.performRestart(Activity.java:6063)
at android.app.ActivityThread.handleWindowVisibility(ActivityThread.java:3473)
at android.app.ActivityThread.access$1200(ActivityThread.java:151)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1337)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:135)
at android.app.ActivityThread.main(ActivityThread.java:5254)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:903)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:698)
Suppressed: java.lang.ClassNotFoundException: myPackage.parcelable_object.Student
at java.lang.Class.classForName(Native Method)
at java.lang.BootClassLoader.findClass(ClassLoader.java:781)
at java.lang.BootClassLoader.loadClass(ClassLoader.java:841)
at java.lang.ClassLoader.loadClass(ClassLoader.java:504)
... 24 more
Caused by: java.lang.NoClassDefFoundError: Class not found using the boot class loader; no stack available08-07 16:26:38.276 10131-10131/myPackage E/AndroidRuntime﹕ FATAL EXCEPTION: main
Process: myPackage, PID: 10131
android.os.BadParcelableException: ClassNotFoundException when unmarshalling: myPackage.parcelable_object.Student
at android.os.Parcel.readParcelableCreator(Parcel.java:2295)
at android.os.Parcel.readParcelable(Parcel.java:2245)
at android.os.Parcel.readValue(Parcel.java:2152)
at android.os.Parcel.readArrayMapInternal(Parcel.java:2485)
at android.os.BaseBundle.unparcel(BaseBundle.java:221)
at android.os.Bundle.getParcelable(Bundle.java:755)
at myPackage.MainActivity.onActivityReenter(MainActivity.java:211)
at android.app.ActivityTransitionState.setEnterActivityOptions(ActivityTransitionState.java:164)
at android.app.Activity.performStart(Activity.java:6002)
at android.app.Activity.performRestart(Activity.java:6063)
at android.app.ActivityThread.handleWindowVisibility(ActivityThread.java:3473)
at android.app.ActivityThread.access$1200(ActivityThread.java:151)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1337)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:135)
at android.app.ActivityThread.main(ActivityThread.java:5254)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:903)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:698)
来源:https://stackoverflow.com/questions/31876767/intent-not-working-for-parcelable-objects-in-onactivityreenter-with-sharedelemen