我的应用程序中有一个活动,它正在访问来自其他应用程序的活动以完成某些任务(这可能是从 Play 商店应用程序下载的应用程序),我在按钮单击侦听器中使用以下代码启动活动,
Intent i=new Intent();
i.setComponent(new ComponentName("com.myapp.package", "com.myapp.package.className"));
i.setAction(Intent.ACTION_MAIN);
startActivity(i);
如果另一个应用程序有一些崩溃,并且做错了什么并且它崩溃了。
结果我的应用程序被活动管理器静默杀死,请在日志下方找到,
02-26 17:39:31.469 281 532 I ActivityManager: START {act=android.intent.action.MAIN flg=0x14000000 cmp=com.example.dummy.mydummyapp2.DummyApp2 (has extras) u=0} from pid 8487
02-26 17:39:31.469 281 532 W WindowManager: Failure taking screenshot for (230x143) to layer 22000
02-26 17:39:31.541 16816 16816 E AndroidRuntime: FATAL EXCEPTION: main
02-26 17:39:31.541 16816 16816 E AndroidRuntime: java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.dummy.mydummyapp2/com.example.dummy.mydummyapp2.DummyApp2}: java.lang.NullPointerException
02-26 17:39:31.541 16816 16816 E AndroidRuntime: at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2059)
02-26 17:39:31.541 16816 16816 E AndroidRuntime: at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2084)
02-26 17:39:31.541 16816 16816 E AndroidRuntime: at android.app.ActivityThread.access$600(ActivityThread.java:130)
02-26 17:39:31.541 16816 16816 E AndroidRuntime: at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1195)
02-26 17:39:31.541 16816 16816 E AndroidRuntime: at android.os.Handler.dispatchMessage(Handler.java:99)
02-26 17:39:31.541 16816 16816 E AndroidRuntime: at android.os.Looper.loop(Looper.java:137)
02-26 17:39:31.541 16816 16816 E AndroidRuntime: at android.app.ActivityThread.main(ActivityThread.java:4745)
02-26 17:39:31.541 16816 16816 E AndroidRuntime: at java.lang.reflect.Method.invokeNative(Native Method)
02-26 17:39:31.541 16816 16816 E AndroidRuntime: at java.lang.reflect.Method.invoke(Method.java:511)
02-26 17:39:31.541 16816 16816 E AndroidRuntime: at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:786)
02-26 17:39:31.541 16816 16816 E AndroidRuntime: at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
02-26 17:39:31.541 16816 16816 E AndroidRuntime: at dalvik.system.NativeStart.main(Native Method)
02-26 17:39:31.541 16816 16816 E AndroidRuntime: Caused by: java.lang.NullPointerException
02-26 17:39:31.541 16816 16816 E AndroidRuntime: at com.example.dummy.mydummyapp2.DummyProvider.search(DummyProvider.java:136)
02-26 17:39:31.541 16816 16816 E AndroidRuntime: at com.example.dummy.mydummyapp2.DummyApp2.onCreate(DummyApp2.java:115)
02-26 17:39:31.541 16816 16816 E AndroidRuntime: at android.app.Activity.performCreate(Activity.java:5008)
02-26 17:39:31.541 16816 16816 E AndroidRuntime: at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1079)
.
.
02-26 17:39:31.553 281 24382 W ActivityManager: Force finishing activity com.example.dummy.mydummyapp2/.DummyApp2
02-26 17:39:31.553 281 24382 W WindowManager: Failure taking screenshot for (230x143) to layer 22015
*****02-26 17:39:31.553 281 24382 W ActivityManager: Force finishing activity com.example.dummy.mydummyapp1/.activities.DummyApp1*****
02-26 17:39:32.053 281 294 W ActivityManager: Activity pause timeout for ActivityRecord{a7082df0 com.example.dummy.mydummyapp2/.DummyApp2}
02-26 17:39:32.437 281 281 I ActivityManager: No longer want com.google.android.partnersetup (pid 31498): hidden #16
*02-26 17:39:42.437 281 294 W ActivityManager: Activity destroy timeout for ActivityRecord{a7082df0 com.example.dummy.mydummyapp2/.DummyApp2}*
02-26 17:40:16.265 281 24383 I ActivityManager: Process com.example.dummy.mydummyapp2 (pid 16816) has died.
02-26 17:44:10.305 281 444 W ThrottleService: unable to find stats for iface rmnet0
我不担心 dummyapp2 的崩溃,我只担心我的应用程序为什么会因为其他应用程序的崩溃而崩溃。
我在意图中尝试了不同的标志,如下所示,
i.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
和
i.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
i.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
但没有结果。
这是android的正常行为吗,如果我的应用程序从其他应用程序启动一个活动并且其他应用程序崩溃了我的应用程序也崩溃了??????
请有人澄清一下,我被卡住了。
问候,