2

我正在研究 Android 中的共享元素转换,并完美地执行了动画。我面临的问题是使用 Intents 传递数据时。所以,我基本上从 ActivityA 启动 Intent,它是包含回收器视图的第一个屏幕,使用 TransitionName 执行 ImageTransform 并启动 ActivityB,其中包含包含 ViewPager 的详细信息活动。现在,当我按下返回按钮时,ActivityB 调用 finishAfterTransition 在其中我创建一个 Intent 并将结果设置如下:

@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();
}

学生模型与此链接中的回答相同。在 ActivityA 中,我正在使用

 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);
 } 

引发以下异常。

当我不传递学生对象并且一切都按预期工作时,所有动画都工作得很好,没有抛出任何异常。我还使用 setEnterSharedElementCallback 和 setExitSharedElementCallback 来映射视图及其转换名称,这与 Intent 无关。

我不明白为什么在 Intent 中传递一个 parcelable 对象不适用于转换。有解决方法还是我做错了?将不胜感激的建议。我在这里只展示了相关的代码。

 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)
4

0 回答 0