有 Java 编程相关的问题?

你可以在下面搜索框中键入要查询的问题!

java Google Maps TransactionTooLargeException

我正以正常的目的启动谷歌地图,并启动覆盖按钮服务返回我的应用程序

Intent iconServiceIntent = new Intent(MainActivity.this, FloatingMapIconService.class);
final String mapsUri = "com.google.安卓.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();

Google Maps崩溃,但出现以下异常:

Process: com.google.安卓.apps.maps, PID: 4586
    java.lang.RuntimeException: tname=main - 安卓.os.TransactionTooLargeException: data parcel size 2832148 bytes
    at 安卓.app.ActivityThread$StopInfo.run(ActivityThread.java:4209)
    at 安卓.os.Handler.handleCallback(Handler.java:751)
    at 安卓.os.Handler.dispatchMessage(Handler.java:95)
    at 安卓.os.Looper.loop(Looper.java:154)
    at 安卓.app.ActivityThread.main(ActivityThread.java:6776)
    at java.lang.reflect.Method.invoke(Native Method)
    at com.安卓.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1496)
    at com.安卓.internal.os.ZygoteInit.main(ZygoteInit.java:1386)
Caused by: 安卓.os.TransactionTooLargeException: data parcel size 2832148 bytes
    at 安卓.os.BinderProxy.transactNative(Native Method)
    at 安卓.os.BinderProxy.transact(Binder.java:628)
    at 安卓.app.ActivityManagerProxy.activityStopped(ActivityManagerNative.java:4183)
    at 安卓.app.ActivityThread$StopInfo.run(ActivityThread.java:4201)
    at 安卓.os.Handler.handleCallback(Handler.java:751) 
    at 安卓.os.Handler.dispatchMessage(Handler.java:95) 
    at 安卓.os.Looper.loop(Looper.java:154) 
    at 安卓.app.ActivityThread.main(ActivityThread.java:6776) 
    at java.lang.reflect.Method.invoke(Native Method) 
    at com.安卓.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1496) 
    at com.安卓.internal.os.ZygoteInit.main(ZygoteInit.java:1386) 

我不知道我做错了什么,所以地图崩溃了?我的FloatingMapIconSerivce类中的Intent标志有问题吗?我想清除堆栈,因此如果用户按下后退按钮,他应该返回到地图或返回到主屏幕,而不是屏幕中的前一个MainActivity 任务堆栈


共 (1) 个答案

  1. # 1 楼答案

    TransactionTooLargeException发生在您尝试在intent中传递大型捆绑包时。在N个设备之下,异常在android N之下处理,但在android版本N及以上的设备之下,异常不被处理

    https://developer.android.com/reference/android/os/TransactionTooLargeException.html

    谷歌建议将所有交易规模保持在非常小的水平。启动活动时,请检查意图和捆绑数据的大小