Error when trying to start a MapActivity from another Activity
When I want to start MapActivity from another activity using this code :
Intent i = new Intent(getBaseContext(),RoutingMapActivity.class);
getApplicationContext().startActivity(i);
I get this error :
09-16 18:47:12.788: ERROR/AndroidRuntime(523): FATAL EXCEPTION: main
09-16 18:47:12.788: ERROR/AndroidRuntime(523): android.util.AndroidRuntimeException: Calling startActivity() from outside of an Activity context requires the FLAG_ACTIVITY_NEW_TASK flag. Is this really what you want?
09-16 18:47:12.788: ERROR/AndroidRuntime(523): at android.app.ContextImpl.startActivity(ContextImpl.java:618)
09-16 18:47:12.788: ERROR/AndroidRuntime(523): at android.content.ContextWrapper.startActivity(ContextWrapper.java:258)
09-16 18:47:12.788: ERROR/AndroidRuntime(523): at com.android.uis.RoutActivity$1.onItemClick(RoutActivity.java:24)
09-16 18:47:12.788: ERROR/AndroidRuntime(523): at android.widget.AdapterView.performItemClick(AdapterView.java:284)
09-16开发者_开发知识库 18:47:12.788: ERROR/AndroidRuntime(523): at android.widget.ListView.performItemClick(ListView.java:3513)
09-16 18:47:12.788: ERROR/AndroidRuntime(523): at android.widget.AbsListView$PerformClick.run(AbsListView.java:1800)
09-16 18:47:12.788: ERROR/AndroidRuntime(523): at android.os.Handler.handleCallback(Handler.java:587)
09-16 18:47:12.788: ERROR/AndroidRuntime(523): at android.os.Handler.dispatchMessage(Handler.java:92)
09-16 18:47:12.788: ERROR/AndroidRuntime(523): at android.os.Looper.loop(Looper.java:123)
09-16 18:47:12.788: ERROR/AndroidRuntime(523): at android.app.ActivityThread.main(ActivityThread.java:3647)
09-16 18:47:12.788: ERROR/AndroidRuntime(523): at java.lang.reflect.Method.invokeNative(Native Method)
09-16 18:47:12.788: ERROR/AndroidRuntime(523): at java.lang.reflect.Method.invoke(Method.java:507)
09-16 18:47:12.788: ERROR/AndroidRuntime(523): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
09-16 18:47:12.788: ERROR/AndroidRuntime(523): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
09-16 18:47:12.788: ERROR/AndroidRuntime(523): at dalvik.system.NativeStart.main(Native Method)
i.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
this solved the problem
If you are starting MapActivity
from an Activity
, why use the application Context
?
Just call Activity
's method startActivity(i)
.
That's basically what you can read in the exception message in the trace.
精彩评论