I understand this topic has been covered a few times, and often the proposed solution to having 'multiple' MapActivity classes is to run one in a different processes. I don't want to do this, I've got 3.
I've instead refactored one MapActivity Subclass to operate in 3 different modes.
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;
}
}
I'm allowing multiple instances of the MapActivity to reside within the task stack, as it's launch mode is still set as 'Standard'. This approach seems to work ok, and I'm not getting the Connection Pool Shutdown message that some seem to get, I'm a little confused as to whether multiple MapActivity instances actually exist or whether android is reusing one automatically?
I am however getting this error, which I don't know how serious it is:
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.开发者_StackOverflow433: 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)
Am I taking the correct approach to this? Should I be concerned with that error?
I got the same problem and after searching I found this post about the same issue
https://novoda.lighthouseapp.com/projects/63622/tickets/157-leak-receiver-searchresult
it suggests that the problem rises when using multiple map activities
within your application.
so in manifest.xml file of my app I made each map activity run in a separate process:
android:process=":p1"
android:process=":p2"
you can read more about this in Android docs. http://developer.android.com/guide/topics/manifest/activity-element.html#proc
精彩评论