我正在使用普通 Intent 启动 Google 地图,并启动一个覆盖按钮服务以返回到我的应用程序。
Intent iconServiceIntent = new Intent(MainActivity.this, FloatingMapIconService.class);
final String mapsUri = "com.google.android.apps.maps";
// lastRequestedAddress is e.g. "Berlin"
Uri intentUri = Uri.parse(String.format("google.navigation:q=%s&mode=b", lastRequestedAddress));
Intent mapIntent = new Intent(Intent.ACTION_VIEW, intentUri);
mapIntent.setPackage(mapsUri);
if (mapIntent.resolveActivity(getPackageManager()) != null) {
startActivity(mapIntent);
startService(iconServiceIntent);
}
点击叠加按钮时:
Intent intent = new Intent(FloatingMapIconService.this, MainActivity.class);
intent.addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP | Intent.FLAG_ACTIVITY_CLEAR_TOP);
FloatingMapIconService.this.startActivity(intent);
//stopping the service
FloatingMapIconService.this.stopSelf();
谷歌地图崩溃并显示以下异常:
Process: com.google.android.apps.maps, PID: 4586
java.lang.RuntimeException: tname=main - android.os.TransactionTooLargeException: data parcel size 2832148 bytes
at android.app.ActivityThread$StopInfo.run(ActivityThread.java:4209)
at android.os.Handler.handleCallback(Handler.java:751)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:154)
at android.app.ActivityThread.main(ActivityThread.java:6776)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1496)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1386)
Caused by: android.os.TransactionTooLargeException: data parcel size 2832148 bytes
at android.os.BinderProxy.transactNative(Native Method)
at android.os.BinderProxy.transact(Binder.java:628)
at android.app.ActivityManagerProxy.activityStopped(ActivityManagerNative.java:4183)
at android.app.ActivityThread$StopInfo.run(ActivityThread.java:4201)
at android.os.Handler.handleCallback(Handler.java:751)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:154)
at android.app.ActivityThread.main(ActivityThread.java:6776)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1496)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1386)
我不知道我做错了什么,导致地图崩溃?我的类中的标志是否有问题?我想清除堆栈,这样如果用户按下返回按钮,他应该返回到地图或返回到主屏幕,而不是返回到任务堆栈中的以前的。