我的应用程序中有一个活动正在访问某个其他应用程序的活动以完成某项任务(这可能是从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的正常行为, 如果我的应用程序从其他应用程序启动一个活动而另一个应用程序崩溃我的应用程序也崩溃了???????
请有人澄清,我被困住了。
此致
答案 0 :(得分:0)
如果其他活动是特定的,(我使用了类似的条形码阅读器活动)你可以使用startActivityForResult,
我使用了类似的东西并为我工作,我希望它也适合你,
Intent intent = new Intent("com.google.zxing.client.android.SCAN");
intent.putExtra("SCAN_MODE", "QR_CODE");
startActivityForResult(intent, 23);
和ActivityResult,
public void onActivityResult(int requestCode, int resultCode, Intent intent) {
if (requestCode == 23) {
if (resultCode == RESULT_OK) {
// use result values
final String contents = intent.getStringExtra("SCAN_RESULT");
final String format = intent.getStringExtra("SCAN_RESULT_FORMAT");
//dosmthng
}
}
}
做出回归意图的事情。
在我的应用程序中,如果条形码阅读器应用程序崩溃我的应用程序仍然有效。
答案 1 :(得分:0)
请尝试围绕try{}
catch{}
块中对其他活动/应用程序的调用,错误日志显示NullPointerException
,您可以通过这种方式控制崩溃。