我正在尝试从活动启动股票主屏幕,但它一直强制关闭。到目前为止,我有一个显示已安装“家”列表的活动。用户可以选择一个,它将启动所选的主屏幕。这适用于已安装的房屋,但是当我选择库存(预安装)房屋时,它将强制关闭。
这是我用来开始活动的内容。我packagename
为我的设备提供了库存主页。
Intent startMain = getPackageManager().getLaunchIntentForPackage("com.android.launcher");
startMain.addCategory(Intent.CATEGORY_HOME);
startMain.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(startMain);
任何帮助都会很棒,因为我不明白为什么这适用于大多数家庭而不适用于其他家庭。
原木猫:
02-01 20:26:46.144: E/AndroidRuntime(7432): FATAL EXCEPTION: main
02-01 20:26:46.144: E/AndroidRuntime(7432): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.calsto.lockscreen/com.calsto.HomeWizard.NanohaLauncher}: java.lang.NullPointerException
02-01 20:26:46.144: E/AndroidRuntime(7432): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1956)
02-01 20:26:46.144: E/AndroidRuntime(7432): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1981)
02-01 20:26:46.144: E/AndroidRuntime(7432): at android.app.ActivityThread.access$600(ActivityThread.java:123)
02-01 20:26:46.144: E/AndroidRuntime(7432): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1147)
02-01 20:26:46.144: E/AndroidRuntime(7432): at android.os.Handler.dispatchMessage(Handler.java:99)
02-01 20:26:46.144: E/AndroidRuntime(7432): at android.os.Looper.loop(Looper.java:137)
02-01 20:26:46.144: E/AndroidRuntime(7432): at android.app.ActivityThread.main(ActivityThread.java:4424)
02-01 20:26:46.144: E/AndroidRuntime(7432): at java.lang.reflect.Method.invokeNative(Native Method)
02-01 20:26:46.144: E/AndroidRuntime(7432): at java.lang.reflect.Method.invoke(Method.java:511)
02-01 20:26:46.144: E/AndroidRuntime(7432): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:787)
02-01 20:26:46.144: E/AndroidRuntime(7432): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:554)
02-01 20:26:46.144: E/AndroidRuntime(7432): at dalvik.system.NativeStart.main(Native Method)
02-01 20:26:46.144: E/AndroidRuntime(7432): Caused by: java.lang.NullPointerException
02-01 20:26:46.144: E/AndroidRuntime(7432): at android.app.Instrumentation.execStartActivity(Instrumentation.java:1378)
02-01 20:26:46.144: E/AndroidRuntime(7432): at android.app.Activity.startActivityForResult(Activity.java:3190)
02-01 20:26:46.144: E/AndroidRuntime(7432): at android.app.Activity.startActivity(Activity.java:3297)
02-01 20:26:46.144: E/AndroidRuntime(7432): at com.calsto.HomeWizard.NanohaLauncher.onCreate(NanohaLauncher.java:233)
02-01 20:26:46.144: E/AndroidRuntime(7432): at android.app.Activity.performCreate(Activity.java:4465)
02-01 20:26:46.144: E/AndroidRuntime(7432): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1049)
02-01 20:26:46.144: E/AndroidRuntime(7432): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1920)
02-01 20:26:46.144: E/AndroidRuntime(7432): ... 11 more