我有一个应用程序,用户可以点击我的应用程序中的某些按钮,它将启动从Android到用户的特定设置页面。我使用他们网站http://developer.android.com/reference/android/provider/Settings.html
中的android APIIntent intent = new Intent(Settings.ACTION_SECURITY_SETTINGS);
currentContext.startActivity(intent);
Intent intent = new Intent(Settings.ACTION_DISPLAY_SETTINGS);
currentContext.startActivity(intent);
这些是我的应用程序将打开的一些设置页面。到目前为止,我从我的应用程序启动这两个意图没有问题。但是,当我尝试使用下面的代码启动“关于平板电脑”页面时,“设置”进程崩溃。
Intent intent = new Intent(Settings.ACTION_DEVICE_INFO_SETTINGS);
currentContext.startActivity(intent);
它在Android 4.1.1上崩溃,但它在Android 3.2上工作正常。我还是Android的新手,我迷失了它崩溃的原因。我也是StackOverflow的新手。希望我能在这里得到一些答案,很高兴认识你们。
这是我的logcat:
09-19 09:50:12.830: I/ActivityManager(270): START {act=android.settings.DEVICE_INFO_SETTINGS cmp=com.android.settings/.Settings$DeviceInfoSettingsActivity u=0} from pid 1627
09-19 09:50:12.910: D/dalvikvm(270): GC_FOR_ALLOC freed 738K, 13% free 11824K/13575K, paused 62ms, total 62ms
09-19 09:50:13.010: W/System.err(1675): Removed 2131231183
09-19 09:50:13.020: W/System.err(1675): Removed 2131231190
09-19 09:50:13.060: D/LocalBluetoothProfileManager(1675): LocalBluetoothProfileManager construction complete
09-19 09:50:13.060: D/AndroidRuntime(1675): Shutting down VM
09-19 09:50:13.060: W/dalvikvm(1675): threadid=1: thread exiting with uncaught exception (group=0x40d4c300)
09-19 09:50:13.060: E/AndroidRuntime(1675): FATAL EXCEPTION: main
09-19 09:50:13.060: E/AndroidRuntime(1675): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.android.settings/com.android.settings.Settings$DeviceInfoSettingsActivity}: java.lang.NullPointerException
09-19 09:50:13.060: E/AndroidRuntime(1675): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2059)
09-19 09:50:13.060: E/AndroidRuntime(1675): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2084)
09-19 09:50:13.060: E/AndroidRuntime(1675): at android.app.ActivityThread.access$600(ActivityThread.java:130)
09-19 09:50:13.060: E/AndroidRuntime(1675): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1195)
09-19 09:50:13.060: E/AndroidRuntime(1675): at android.os.Handler.dispatchMessage(Handler.java:99)
09-19 09:50:13.060: E/AndroidRuntime(1675): at android.os.Looper.loop(Looper.java:137)
09-19 09:50:13.060: E/AndroidRuntime(1675): at android.app.ActivityThread.main(ActivityThread.java:4745)
09-19 09:50:13.060: E/AndroidRuntime(1675): at java.lang.reflect.Method.invokeNative(Native Method)
09-19 09:50:13.060: E/AndroidRuntime(1675): at java.lang.reflect.Method.invoke(Method.java:511)
09-19 09:50:13.060: E/AndroidRuntime(1675): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:786)
09-19 09:50:13.060: E/AndroidRuntime(1675): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
09-19 09:50:13.060: E/AndroidRuntime(1675): at dalvik.system.NativeStart.main(Native Method)
09-19 09:50:13.060: E/AndroidRuntime(1675): Caused by: java.lang.NullPointerException
09-19 09:50:13.060: E/AndroidRuntime(1675): at com.android.settings.Settings.onCreate(Settings.java:167)
09-19 09:50:13.060: E/AndroidRuntime(1675): at android.app.Activity.performCreate(Activity.java:5008)
09-19 09:50:13.060: E/AndroidRuntime(1675): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1079)
09-19 09:50:13.060: E/AndroidRuntime(1675): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2023)
09-19 09:50:13.060: E/AndroidRuntime(1675): ... 11 more
09-19 09:50:13.090: W/ActivityManager(270): Force finishing activity com.android.settings/.Settings$DeviceInfoSettingsActivity
09-19 09:50:13.090: W/ActivityManager(270): Force finishing activity com.panasonic.tbexperience/.view.templates.TwoColumnsControlActivity
09-19 09:50:13.100: W/InputMethodManagerService(270): Window already focused, ignoring focus gain of: com.android.internal.view.IInputMethodClient$Stub$Proxy@41811de8 attribute=null
09-19 09:50:13.130: D/dalvikvm(1675): GC_CONCURRENT freed 187K, 4% free 6233K/6471K, paused 12ms+5ms, total 60ms
09-19 09:50:13.610: W/ActivityManager(270): Activity pause timeout for ActivityRecord{417ea2e0 com.android.settings/.Settings$DeviceInfoSettingsActivity}
09-19 09:50:13.820: D/dalvikvm(445): GC_FOR_ALLOC freed 1020K, 33% free 14790K/22023K, paused 41ms, total 41ms
09-19 09:50:13.960: D/dalvikvm(445): GC_FOR_ALLOC freed 1057K, 30% free 15633K/22023K, paused 39ms, total 39ms
09-19 09:50:14.010: D/dalvikvm(445): GC_FOR_ALLOC freed 362K, 24% free 16871K/22023K, paused 32ms, total 32ms
09-19 09:50:14.060: D/dalvikvm(445): GC_CONCURRENT freed 1289K, 20% free 17622K/22023K, paused 3ms+7ms, total 39ms
09-19 09:50:14.060: D/dalvikvm(445): WAIT_FOR_CONCURRENT_GC blocked 29ms
09-19 09:50:14.060: D/dalvikvm(445): WAIT_FOR_CONCURRENT_GC blocked 17ms
09-19 09:50:14.100: D/dalvikvm(445): GC_FOR_ALLOC freed 1693K, 25% free 16723K/22023K, paused 31ms, total 31ms
09-19 09:50:14.190: D/dalvikvm(445): GC_CONCURRENT freed 1126K, 21% free 17585K/22023K, paused 14ms+9ms, total 64ms
09-19 09:50:14.190: D/dalvikvm(445): WAIT_FOR_CONCURRENT_GC blocked 50ms
09-19 09:50:14.390: I/dalvikvm(270): Jit: resizing JitTable from 8192 to 16384
09-19 09:50:16.870: I/Process(1675): Sending signal. PID: 1675 SIG: 9
09-19 09:50:16.890: I/ActivityManager(270): Process com.android.settings (pid 1675) has died.
09-19 09:50:16.890: W/ActivityManager(270): Force removing ActivityRecord{4166f668 com.android.settings/.Settings$DeviceInfoSettingsActivity}: app died, no saved state
09-19 09:50:16.890: W/InputMethodManagerService(270): Window already focused, ignoring focus gain of: com.android.internal.view.IInputMethodClient$Stub$Proxy@415f2878 attribute=null
09-19 09:50:32.250: D/dalvikvm(1552): GC_CONCURRENT freed 424K, 9% free 6942K/7559K, paused 12ms+3ms, total 39ms
另外,我试图直接设置此api的类名...
Intent intent = new Intent();
intent.setClassName("com.android.settings", "com.android.settings.Settings$DeviceInfoSettingsActivity");
currentContext.startActivity(intent);
同样的事情发生。它适用于Android 3.2,但在4.1.1中不起作用。我有一种感觉,也许我没有为4.1.1版本获得正确的类名。有没有人知道直接类名来打开“关于平板电脑”页面,或者是否可以通过编程方式打开该页面?
此致 竖纹
答案 0 :(得分:0)
android api doc说:
In some cases, a matching Activity may not exist, so ensure you safeguard against this.
因此您应该检查此意图或自己捕获此异常。