gpt4 book ai didi

android - 堆栈中的多个 MapActivity

转载 作者:太空宇宙 更新时间:2023-11-03 12:42:45 25 4
gpt4 key购买 nike

我知道这个话题已经被讨论过几次了,而且对于拥有“多个”MapActivity 类的建议解决方案通常是在不同的进程中运行一个。我不想这样做,我有 3 个。

我重构了一个 MapActivity 子类以在 3 种不同模式下运行。


package com.rossgreenhalf.maptest.activity;

import android.os.Bundle;

import com.google.android.maps.MapActivity;

public class MyMapActivity extends MapActivity {

@Override
protected void onCreate(Bundle icicle) {
super.onCreate(icicle);

/* Inflate xml view, Set Zoom etc */
}

@Override
protected void onResume() {
super.onResume();

int mode = getIntent().getExtras().getInt("MAP_MODE");

switch(mode){
case 1:
/* Some markers to show */
break;
case 2:
/* Just one Marker */
break;
case 3:
/* Only showing my location */
break;
}
}

@Override
protected boolean isRouteDisplayed() {
return false;
}
}

我允许 MapActivity 的多个实例驻留在任务堆栈中,因为它的启动模式仍设置为“标准”。这种方法似乎工作正常,我没有收到某些人似乎收到的连接池关闭消息,我有点困惑是否确实存在多个 MapActivity 实例,或者 android 是否自动重用一个实例?

但是我收到了这个错误,我不知道它有多严重:


01-25 10:14:54.433: ERROR/ActivityThread(5620): Activity com.rossgreenhalf.maptest.activity.MyMapActivity has leaked IntentReceiver com.google.android.maps.NetworkConnectivityListener$ConnectivityBroadcastReceiver@44981cf0 that was originally registered here. Are you missing a call to unregisterReceiver()?
01-25 10:14:54.433: ERROR/ActivityThread(5620): android.app.IntentReceiverLeaked: Activity com.rossgreenhalf.maptest.activity.MyMapActivity has leaked IntentReceiver com.google.android.maps.NetworkConnectivityListener$ConnectivityBroadcastReceiver@44981cf0 that was originally registered here. Are you missing a call to unregisterReceiver()?
01-25 10:14:54.433: ERROR/ActivityThread(5620): at android.app.ActivityThread$PackageInfo$ReceiverDispatcher.(ActivityThread.java:968)
01-25 10:14:54.433: ERROR/ActivityThread(5620): at android.app.ActivityThread$PackageInfo.getReceiverDispatcher(ActivityThread.java:753)
01-25 10:14:54.433: ERROR/ActivityThread(5620): at android.app.ContextImpl.registerReceiverInternal(ContextImpl.java:799)
01-25 10:14:54.433: ERROR/ActivityThread(5620): at android.app.ContextImpl.registerReceiver(ContextImpl.java:786)
01-25 10:14:54.433: ERROR/ActivityThread(5620): at android.app.ContextImpl.registerReceiver(ContextImpl.java:780)
01-25 10:14:54.433: ERROR/ActivityThread(5620): at android.content.ContextWrapper.registerReceiver(ContextWrapper.java:318)
01-25 10:14:54.433: ERROR/ActivityThread(5620): at com.google.android.maps.NetworkConnectivityListener.startListening(MapActivity.java:163)
01-25 10:14:54.433: ERROR/ActivityThread(5620): at com.google.android.maps.MapActivity.onResume(MapActivity.java:431)
01-25 10:14:54.433: ERROR/ActivityThread(5620): at com.rossgreenhalf.maptest.activity.MyMapActivity.onResume(MyMapActivity.java:166)
01-25 10:14:54.433: ERROR/ActivityThread(5620): at android.app.Instrumentation.callActivityOnResume(Instrumentation.java:1237)
01-25 10:14:54.433: ERROR/ActivityThread(5620): at android.app.Activity.performResume(Activity.java:3864)
01-25 10:14:54.433: ERROR/ActivityThread(5620): at android.app.ActivityThread.performResumeActivity(ActivityThread.java:3315)
01-25 10:14:54.433: ERROR/ActivityThread(5620): at android.app.ActivityThread.handleResumeActivity(ActivityThread.java:3340)
01-25 10:14:54.433: ERROR/ActivityThread(5620): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2158)
01-25 10:14:54.433: ERROR/ActivityThread(5620): at android.os.Handler.dispatchMessage(Handler.java:99)
01-25 10:14:54.433: ERROR/ActivityThread(5620): at android.os.Looper.loop(Looper.java:143)
01-25 10:14:54.433: ERROR/ActivityThread(5620): at android.app.ActivityThread.main(ActivityThread.java:4914)
01-25 10:14:54.433: ERROR/ActivityThread(5620): at java.lang.reflect.Method.invokeNative(Native Method)
01-25 10:14:54.433: ERROR/ActivityThread(5620): at java.lang.reflect.Method.invoke(Method.java:521)
01-25 10:14:54.433: ERROR/ActivityThread(5620): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:858)
01-25 10:14:54.433: ERROR/ActivityThread(5620): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
01-25 10:14:54.433: ERROR/ActivityThread(5620): at dalvik.system.NativeStart.main(Native Method)

我对此采取了正确的方法吗?我应该担心那个错误吗?

最佳答案

我遇到了同样的问题,搜索后我发现了这篇关于同样问题的帖子

https://novoda.lighthouseapp.com/projects/63622/tickets/157-leak-receiver-searchresult

这表明在您的应用程序中使用多个 map activity 时会出现问题。

所以在我的应用程序的 ma​​nifest.xml 文件中,我让每个 map Activity 在一个单独的进程中运行:

android:process=":p1"
android:process=":p2"

您可以在 Android 文档中阅读更多相关信息。 http://developer.android.com/guide/topics/manifest/activity-element.html#proc

关于android - 堆栈中的多个 MapActivity,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4792265/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com