在 ART 环境中,它无法传递复杂的 Parcelable 对象。
存在从实现Parcelable的类的内部类的CREATOR的Parcel的内部处理调用另一个类的CREATOR的情况。它将采取不同类别的反射领域是当读取 Parcel 内的 Parcelable 类时到期。
例如:
- ListParamDto.java 实现 Parcelable。
- DetailParamDto.java 扩展 ListParamDto.java
- intent.putExtra(detailParamDto.getClass().getCanonicalName(), DetailParamDto) 和 startActivity(intent)。
2133 行 API 19 Parcel.java https://github.com/android/platform_frameworks_base/blob/master/core/java/android/os/Parcel.java#L2139
Class c = loader == null ? Class.forName(name) : Class.forName(name, true, loader); // name's value is DetailParamDto
Field f = c.getField("CREATOR"); //f indicates the field of DetailParamDto
creator = (Parcelable.Creator)f.get(null); // ←result of get, the value that is set to creator becomes the RentListParamDto $ CREATOR
它在 Dalvik 环境中进展顺利。
我附上了堆栈跟踪日志,
05-27 04:22:39.203 2254-2254/jp.co.xxxx.android.app E/AndroidRuntime﹕ FATAL EXCEPTION: main
Process: jp.co.xxx.android.app, PID: 2254
java.lang.RuntimeException: Unable to start activity ComponentInfo{jp.co.xxx.android.app/jp.co.xxx.android.app.activity.buy.BuylActivity}: java.lang.RuntimeException: Parcel android.os.Parcel@64ea3a48: Unmarshalling unknown type code 3276852 at offset 2512
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2195)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2245)
at android.app.ActivityThread.access$800(ActivityThread.java:135)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1196)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:136)
at android.app.ActivityThread.main(ActivityThread.java:5017)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:779)s
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:595)
Caused by: java.lang.RuntimeException: Parcel android.os.Parcel@64ea3a48: Unmarshalling unknown type code 3276852 at offset 2512
at android.os.Parcel.readValue(Parcel.java:2080)
at android.os.Parcel.readArrayMapInternal(Parcel.java:2313)
at android.os.Bundle.unparcel(Bundle.java:249)
at android.os.Bundle.getBoolean(Bundle.java:858)
at android.content.Intent.getBooleanExtra(Intent.java:4490)
at jp.co.xxx.android.app.activity.BaseActivity.onCreate(BaseActivity.java:98)
at jp.co.xxx.android.app.activity.buy.DetailBaseActivity.onCreate(DetailBaseActivity.java:126)
at android.app.Activity.performCreate(Activity.java:5231)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1087)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2159)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2245)
at android.app.ActivityThread.access$800(ActivityThread.java:135)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1196)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:136)
at android.app.ActivityThread.main(ActivityThread.java:5017)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:779)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:595)
你知道吗?