我有两个活动A和B。在活动A中,我单击一个按钮即可进入活动B。在活动B中,我有一个自定义的viewgroup视图。在此customview中,我想在电话图库中获取图像,因此我习惯((Activity) context).startActivityForResult(i, 1);
进入我的图库。但是在那之后,我的应用程序被杀死(B acivity被杀死)。
有人说我应该在主要活动(B活动)上调用startActivityForResult,因此在customview中,我向活动B发送广播。在活动B中,我收到动作,然后调用startActivityForResult在画廊中选择图像,但是它没有。工作。
案例1:从customview中选择图库中的图片
public void draw_multi(MotionEvent event) {
switch (event.getAction()) {
case MotionEvent.ACTION_DOWN:
Intent intent = new Intent(Intent.ACTION_PICK, MediaStore.Images.Media.EXTERNAL_CONTENT_URI);
((Activity) mContext).startActivityForResult(intent, REQUEST_GET_SINGLE_FILE);
break;
case MotionEvent.ACTION_MOVE:
break;
case MotionEvent.ACTION_UP:
break;
default:
break;
}
}
案例2:在活动B中从customview和接收者发送广播
public void draw_multi(MotionEvent event) {
float x = event.getX() / scale;
float y = event.getY() / scale;
Intent i = new Intent();
i.setAction(ACTION_FILTER);
i.putExtra("action", ACTION_SHOW_NOTIFICATION_MUPDF);
i.putExtra("xLoca", x);
i.putExtra("yLocal", y);
i.putExtra("pageNumber", this.getPageNumber());
mContext.sendBroadcast(i);
}
活动性B中的接收器
private class PDFReceiver extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {
if (intent.getExtras().containsKey("action")) {
String resultAction = intent.getExtras().getString("action");
switch (resultAction) {
case ACTION_SHOW_NOTIFICATION_MUPDF:
Intent i = new Intent(Intent.ACTION_PICK, MediaStore.Images.Media.EXTERNAL_CONTENT_URI);
((Activity) context).startActivityForResult(i, 1);
break;
}
}
}
}
这是错误日志,我尚未从列表中选择图像
java.lang.RuntimeException: android.os.TransactionTooLargeException: data parcel size 3299828 bytes
at android.app.servertransaction.PendingTransactionActions$StopInfo.run(PendingTransactionActions.java:160)
at android.os.Handler.handleCallback(Handler.java:891)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:207)
at android.app.ActivityThread.main(ActivityThread.java:7539)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:524)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:958)
Caused by: android.os.TransactionTooLargeException: data parcel size 3299828 bytes
at android.os.BinderProxy.transactNative(Native Method)
at android.os.BinderProxy.transact(Binder.java:1147)
at android.app.IActivityManager$Stub$Proxy.activityStopped(IActivityManager.java:3981)
at android.app.servertransaction.PendingTransactionActions$StopInfo.run(PendingTransactionActions.java:144)
at android.os.Handler.handleCallback(Handler.java:891)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:207)
at android.app.ActivityThread.main(ActivityThread.java:7539)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:524)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:958) 2019-04-18 23:54:37.148 10237-10237/tve.tve.vnulic I/Process: Sending signal. PID: 10237 SIG: 9
我该如何解决?请帮助我,谢谢!!!