我在服务中有一个Async Task,它试图将ArrayList传递给我的Activity。
ArrayList<Malware> fetch = new ArrayList<Malware>();
@Override
protected void onPostExecute(Void result) {
Intent d = new Intent();
d.setAction(COMPLETED_INTENT);
d.putExtra("CurrentProgress", "completed");
d.putExtra("MalwareArray", fetch);
sendBroadcast(d);
}
我在尝试将arraylist广播到活动时遇到了错误。
11-06 17:58:13.880: E/AndroidRuntime(13645): FATAL EXCEPTION: main
11-06 17:58:13.880: E/AndroidRuntime(13645): java.lang.RuntimeException: Parcel: unable to marshal value com.analyze.project.Malware@414e0510
11-06 17:58:13.880: E/AndroidRuntime(13645): at android.os.Parcel.writeValue(Parcel.java:1137)
11-06 17:58:13.880: E/AndroidRuntime(13645): at android.os.Parcel.writeList(Parcel.java:524)
11-06 17:58:13.880: E/AndroidRuntime(13645): at android.os.Parcel.writeValue(Parcel.java:1097)
11-06 17:58:13.880: E/AndroidRuntime(13645): at android.os.Parcel.writeMapInternal(Parcel.java:493)
11-06 17:58:13.880: E/AndroidRuntime(13645): at android.os.Bundle.writeToParcel(Bundle.java:1612)
11-06 17:58:13.880: E/AndroidRuntime(13645): at android.os.Parcel.writeBundle(Parcel.java:507)
11-06 17:58:13.880: E/AndroidRuntime(13645): at android.content.Intent.writeToParcel(Intent.java:6216)
11-06 17:58:13.880: E/AndroidRuntime(13645): at android.app.ActivityManagerProxy.broadcastIntent(ActivityManagerNative.java:1911)
11-06 17:58:13.880: E/AndroidRuntime(13645): at android.app.ContextImpl.sendBroadcast(ContextImpl.java:961)
11-06 17:58:13.880: E/AndroidRuntime(13645): at android.content.ContextWrapper.sendBroadcast(ContextWrapper.java:301)
11-06 17:58:13.880: E/AndroidRuntime(13645): at com.analyze.project.ScanService$FullScan.onPostExecute(ScanService.java:153)
11-06 17:58:13.880: E/AndroidRuntime(13645): at com.analyze.project.ScanService$FullScan.onPostExecute(ScanService.java:1)
11-06 17:58:13.880: E/AndroidRuntime(13645): at android.os.AsyncTask.finish(AsyncTask.java:602)
11-06 17:58:13.880: E/AndroidRuntime(13645): at android.os.AsyncTask.access$600(AsyncTask.java:156)
11-06 17:58:13.880: E/AndroidRuntime(13645): at android.os.AsyncTask$InternalHandler.handleMessage(AsyncTask.java:615)
11-06 17:58:13.880: E/AndroidRuntime(13645): at android.os.Handler.dispatchMessage(Handler.java:99)
11-06 17:58:13.880: E/AndroidRuntime(13645): at android.os.Looper.loop(Looper.java:137)
11-06 17:58:13.880: E/AndroidRuntime(13645): at android.app.ActivityThread.main(ActivityThread.java:4513)
11-06 17:58:13.880: E/AndroidRuntime(13645): at java.lang.reflect.Method.invokeNative(Native Method)
11-06 17:58:13.880: E/AndroidRuntime(13645): at java.lang.reflect.Method.invoke(Method.java:511)
11-06 17:58:13.880: E/AndroidRuntime(13645): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:974)
11-06 17:58:13.880: E/AndroidRuntime(13645): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:741)
11-06 17:58:13.880: E/AndroidRuntime(13645): at dalvik.system.NativeStart.main(Native Method)
答案 0 :(得分:2)
您需要使对象实现parcelable接口,以便您能够通过intent传递它。
以下是实现此目的的一个很好的例子:
Android Parcelable -- RetailerOrderActivity.java return null