在我的应用程序中,我在设备上启动其他应用程序,如下所示:
Intent LaunchIntent = getPackageManager().getLaunchIntentForPackage(packageName);
if (LaunchIntent == null) return;
LaunchIntent.addCategory(Intent.CATEGORY_LAUNCHER);
LaunchIntent.setAction(Intent.ACTION_MAIN);
LaunchIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED);
startActivity(LaunchIntent);
一切正常,直到执行的应用程序可能崩溃。在这种情况下,我的应用程序也强制关闭。
01-06 20:13:00.796 4560-4560/com.example.android.trivialdrivesample E/AndroidRuntime: FATAL EXCEPTION: main
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.android.trivialdrivesample/com.example.android.trivialdrivesample.MainActivity}: java.lang.RuntimeException: Please change the sample's package name! See README.
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1647)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1663)
at android.app.ActivityThread.access$1500(ActivityThread.java:117)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:931)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:130)
at android.app.ActivityThread.main(ActivityThread.java:3683)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:507)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:850)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:608)
at dalvik.system.NativeStart.main(Native Method)
Caused by: java.lang.RuntimeException: Please change the sample's package name! See README.
at com.example.android.trivialdrivesample.MainActivity.onCreate(MainActivity.java:146)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1611)
... 11 more
01-06 20:13:00.804 1386-1520/? W/ActivityManager: Force finishing activity com.example.android.trivialdrivesample/.MainActivity
01-06 20:13:00.804 1386-1520/? W/ActivityManager: Force finishing activity com.digitalmediarevolutions.kfmobiledesktop/.activities.MainActivity
我应该怎么做才能防止强制关闭我的应用程序?