我PreferenceActivity显示不出来,即使它是在我的清单文件

所以我修改立方体动态壁纸的例子。 我有一个扩展PreferenceActivity一类,我添加了活动在我的清单文件。 我不断收到ActivityNotFoundExceptions。

这里是我的偏好类:

package com.ptwallpapers.mywallpaper; import com.ptwallpapers.mywallpaper.R; import android.content.SharedPreferences; import android.os.Bundle; import android.preference.PreferenceActivity; public class MySettingsActivity extends PreferenceActivity implements SharedPreferences.OnSharedPreferenceChangeListener { @Override protected void onCreate(Bundle bundle) { super.onCreate(bundle); getPreferenceManager().setSharedPreferencesName( ParticleCandy.SHARED_PREFS_NAME); addPreferencesFromResource(R.xml.settings); getPreferenceManager().getSharedPreferences().registerOnSharedPreferenceChangeListener( this); } @Override protected void onResume() { super.onResume(); } @Override protected void onDestroy() { getPreferenceManager().getSharedPreferences().unregisterOnSharedPreferenceChangeListener( this); super.onDestroy(); } public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, String key) { }

}

这里是我的清单文件

<?xml version="1.0" encoding="utf-8"?> <manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.ptwallpapers.mywallpaper" android:versionCode="1" android:versionName="1.0"> <application android:icon="@drawable/icon" android:label="@string/app_name"> <service android:label="@string/app_name" android:name=".MyWallpaper" android:permission="android.permission.BIND_WALLPAPER" > <intent-filter> <action android:name="android.service.wallpaper.WallpaperService"> </action> </intent-filter> <meta-data android:name="android.service.wallpaper" android:resource="@xml/wallpaper_info" /> </service> <activity android:label="@string/settings_title" android:name=".MySettingsActivity" android:theme="@android:style/Theme.Light.WallpaperSettings" android:exported="true"> </activity> </application> <uses-sdk android:minSdkVersion="7" /> <uses-feature android:name="android.software.live_wallpaper" /> </manifest>

任何想法,为什么我的喜好的活动没有得到来自清单读? 墙纸服务,MyWallpaper显示出来就好了,但DDMS不断告诉我活动MySettingsActivity不会退出。

下面是从logcat的输出

04-11 00:22:19.617: INFO/ActivityManager(57): Starting activity: Intent { cmp=com.android.wallpaper.livepicker/.LiveWallpaperPreview (has extras) } 04-11 00:22:21.796: INFO/ActivityManager(57): Displayed activity com.android.wallpaper.livepicker/.LiveWallpaperPreview: 2111 ms (total 2111 ms) 04-11 00:22:25.667: DEBUG/dalvikvm(375): GC freed 4745 objects / 316576 bytes in 192ms 04-11 00:22:25.727: INFO/ActivityManager(57): Starting activity: Intent { cmp=com.ptwallpapers.mywallpaper/MySettingsActivity (has extras) } 04-11 00:22:25.757: DEBUG/AndroidRuntime(375): Shutting down VM 04-11 00:22:25.768: WARN/dalvikvm(375): threadid=3: thread exiting with uncaught exception (group=0x4001b188) 04-11 00:22:25.787: ERROR/AndroidRuntime(375): Uncaught handler: thread main exiting due to uncaught exception 04-11 00:22:25.847: ERROR/AndroidRuntime(375): java.lang.IllegalStateException: Could not execute method of the activity 04-11 00:22:25.847: ERROR/AndroidRuntime(375): at android.view.View$1.onClick(View.java:2031) 04-11 00:22:25.847: ERROR/AndroidRuntime(375): at android.view.View.performClick(View.java:2364) 04-11 00:22:25.847: ERROR/AndroidRuntime(375): at android.view.View.onTouchEvent(View.java:4179) 04-11 00:22:25.847: ERROR/AndroidRuntime(375): at android.widget.TextView.onTouchEvent(TextView.java:6540) 04-11 00:22:25.847: ERROR/AndroidRuntime(375): at android.view.View.dispatchTouchEvent(View.java:3709) 04-11 00:22:25.847: ERROR/AndroidRuntime(375): at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:884) 04-11 00:22:25.847: ERROR/AndroidRuntime(375): at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:884) 04-11 00:22:25.847: ERROR/AndroidRuntime(375): at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:884) 04-11 00:22:25.847: ERROR/AndroidRuntime(375): at com.android.internal.policy.impl.PhoneWindow$DecorView.superDispatchTouchEvent(PhoneWindow.java:1659) 04-11 00:22:25.847: ERROR/AndroidRuntime(375): at com.android.internal.policy.impl.PhoneWindow.superDispatchTouchEvent(PhoneWindow.java:1107) 04-11 00:22:25.847: ERROR/AndroidRuntime(375): at com.android.wallpaper.livepicker.LiveWallpaperPreview.dispatchTouchEvent(LiveWallpaperPreview.java:199) 04-11 00:22:25.847: ERROR/AndroidRuntime(375): at com.android.internal.policy.impl.PhoneWindow$DecorView.dispatchTouchEvent(PhoneWindow.java:1643) 04-11 00:22:25.847: ERROR/AndroidRuntime(375): at android.view.ViewRoot.handleMessage(ViewRoot.java:1691) 04-11 00:22:25.847: ERROR/AndroidRuntime(375): at android.os.Handler.dispatchMessage(Handler.java:99) 04-11 00:22:25.847: ERROR/AndroidRuntime(375): at android.os.Looper.loop(Looper.java:123) 04-11 00:22:25.847: ERROR/AndroidRuntime(375): at android.app.ActivityThread.main(ActivityThread.java:4363) 04-11 00:22:25.847: ERROR/AndroidRuntime(375): at java.lang.reflect.Method.invokeNative(Native Method) 04-11 00:22:25.847: ERROR/AndroidRuntime(375): at java.lang.reflect.Method.invoke(Method.java:521) 04-11 00:22:25.847: ERROR/AndroidRuntime(375): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:860) 04-11 00:22:25.847: ERROR/AndroidRuntime(375): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:618) 04-11 00:22:25.847: ERROR/AndroidRuntime(375): at dalvik.system.NativeStart.main(Native Method) 04-11 00:22:25.847: ERROR/AndroidRuntime(375): Caused by: java.lang.reflect.InvocationTargetException 04-11 00:22:25.847: ERROR/AndroidRuntime(375): at com.android.wallpaper.livepicker.LiveWallpaperPreview.configureLiveWallpaper(LiveWallpaperPreview.java:113) 04-11 00:22:25.847: ERROR/AndroidRuntime(375): at java.lang.reflect.Method.invokeNative(Native Method) 04-11 00:22:25.847: ERROR/AndroidRuntime(375): at java.lang.reflect.Method.invoke(Method.java:521) 04-11 00:22:25.847: ERROR/AndroidRuntime(375): at android.view.View$1.onClick(View.java:2026) 04-11 00:22:25.847: ERROR/AndroidRuntime(375): ... 20 more 04-11 00:22:25.847: ERROR/AndroidRuntime(375): Caused by: android.content.ActivityNotFoundException: Unable to find explicit activity class {com.ptwallpapers.mywallpaper/MySettingsActivity}; have you declared this activity in your AndroidManifest.xml? 04-11 00:22:25.847: ERROR/AndroidRuntime(375): at android.app.Instrumentation.checkStartActivityResult(Instrumentation.java:1404) 04-11 00:22:25.847: ERROR/AndroidRuntime(375): at android.app.Instrumentation.execStartActivity(Instrumentation.java:1378) 04-11 00:22:25.847: ERROR/AndroidRuntime(375): at android.app.Activity.startActivityForResult(Activity.java:2749) 04-11 00:22:25.847: ERROR/AndroidRuntime(375): at android.app.Activity.startActivity(Activity.java:2855) 04-11 00:22:25.847: ERROR/AndroidRuntime(375): ... 24 more 04-11 00:22:25.917: INFO/Process(57): Sending signal. PID: 375 SIG: 3 04-11 00:22:25.917: INFO/dalvikvm(375): threadid=7: reacting to signal 3 04-11 00:22:25.988: ERROR/ActivityThread(57): Failed to find provider info for android.server.checkin 04-11 00:22:26.012: ERROR/Checkin(57): Error reporting crash: java.lang.IllegalArgumentException: Unknown URL content://android.server.checkin/crashes 04-11 00:22:26.044: INFO/dalvikvm(375): Wrote stack trace to '/data/anr/traces.txt' 04-11 00:22:29.307: INFO/Process(375): Sending signal. PID: 375 SIG: 9 04-11 00:22:29.516: INFO/ActivityManager(57): Process android.process.acore (pid 375) has died. 04-11 00:22:29.516: INFO/WindowManager(57): WIN DEATH: Window{44dd50d8 Media:com.android.wallpaper.livepicker/com.android.wallpaper.livepicker.LiveWallpaperPreview paused=false} 04-11 00:22:29.576: INFO/WindowManager(57): WIN DEATH: Window{44d660f8 com.android.wallpaper.livepicker/com.android.wallpaper.livepicker.LiveWallpaperListActivity paused=false} 04-11 00:22:29.586: INFO/WindowManager(57): WIN DEATH: Window{44dbe2f0 com.android.wallpaper.livepicker/com.android.wallpaper.livepicker.LiveWallpaperPreview paused=false} 04-11 00:22:29.876: INFO/ActivityManager(57): Start proc android.process.acore for activity com.android.wallpaper.livepicker/.LiveWallpaperListActivity: pid=421 uid=10022 gids={} 04-11 00:22:30.687: DEBUG/ddm-heap(421): Got feature list request 04-11 00:22:30.957: INFO/UsageStats(57): Unexpected resume of com.android.wallpaper.livepicker while already resumed in com.android.wallpaper.livepicker 04-11 00:22:31.756: WARN/ResourceType(421): getEntry failing because entryIndex 2 is beyond type entryCount 2 04-11 00:22:31.768: WARN/ResourceType(421): Failure getting entry for 0x7f040002 (t=3 e=2) in package 0: 0x80000001 04-11 00:22:32.758: WARN/InputManagerService(57): Got RemoteException sending setActive(false) notification to pid 375 uid 10022 04-11 00:22:33.137: INFO/ActivityManager(57): Displayed activity com.android.wallpaper.livepicker/.LiveWallpaperListActivity: 3430 ms (total 3430 ms) 04-11 00:22:33.528: ERROR/gralloc(57): [unregister] handle 0x467ae8 still locked (state=40000001) 04-11 00:22:38.368: DEBUG/dalvikvm(364): GC freed 611 objects / 51656 bytes in 179ms

更新logcat的

04-11 01:10:52.976: INFO/ActivityManager(57): Starting activity: Intent { act=android.intent.action.CHOOSER cmp=android/com.android.internal.app.ChooserActivity (has extras) } 04-11 01:10:53.668: WARN/InputManagerService(57): Window already focused, ignoring focus gain of: [email protected] 04-11 01:10:54.587: INFO/ActivityManager(57): Displayed activity android/com.android.internal.app.ChooserActivity: 1140 ms (total 17760 ms) 04-11 01:10:56.458: INFO/ActivityManager(57): Starting activity: Intent { act=android.intent.action.SET_WALLPAPER flg=0x3000000 cmp=com.android.wallpaper.livepicker/.LiveWallpaperListActivity } 04-11 01:10:57.466: DEBUG/dalvikvm(1622): GC freed 1487 objects / 106648 bytes in 167ms 04-11 01:10:57.556: WARN/ResourceType(1622): getEntry failing because entryIndex 2 is beyond type entryCount 2 04-11 01:10:57.587: WARN/ResourceType(1622): Failure getting entry for 0x7f040002 (t=3 e=2) in package 0: 0x80000001 04-11 01:10:58.516: INFO/ActivityManager(57): Displayed activity com.android.wallpaper.livepicker/.LiveWallpaperListActivity: 1625 ms (total 1625 ms) 04-11 01:11:00.717: INFO/ActivityManager(57): Starting activity: Intent { cmp=com.android.wallpaper.livepicker/.LiveWallpaperPreview (has extras) } 04-11 01:11:02.948: INFO/ActivityManager(57): Displayed activity com.android.wallpaper.livepicker/.LiveWallpaperPreview: 2187 ms (total 2187 ms) 04-11 01:11:11.538: INFO/ActivityManager(57): Starting activity: Intent { cmp=com.ptwallpapers.mywallpaper/MySettingsActivity (has extras) } 04-11 01:11:11.577: DEBUG/AndroidRuntime(1622): Shutting down VM 04-11 01:11:11.587: WARN/dalvikvm(1622): threadid=3: thread exiting with uncaught exception (group=0x4001b188) 04-11 01:11:11.597: ERROR/AndroidRuntime(1622): Uncaught handler: thread main exiting due to uncaught exception 04-11 01:11:11.667: ERROR/AndroidRuntime(1622): java.lang.IllegalStateException: Could not execute method of the activity 04-11 01:11:11.667: ERROR/AndroidRuntime(1622): at android.view.View$1.onClick(View.java:2031) 04-11 01:11:11.667: ERROR/AndroidRuntime(1622): at android.view.View.performClick(View.java:2364) 04-11 01:11:11.667: ERROR/AndroidRuntime(1622): at android.view.View.onTouchEvent(View.java:4179) 04-11 01:11:11.667: ERROR/AndroidRuntime(1622): at android.widget.TextView.onTouchEvent(TextView.java:6540) 04-11 01:11:11.667: ERROR/AndroidRuntime(1622): at android.view.View.dispatchTouchEvent(View.java:3709) 04-11 01:11:11.667: ERROR/AndroidRuntime(1622): at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:884) 04-11 01:11:11.667: ERROR/AndroidRuntime(1622): at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:884) 04-11 01:11:11.667: ERROR/AndroidRuntime(1622): at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:884) 04-11 01:11:11.667: ERROR/AndroidRuntime(1622): at com.android.internal.policy.impl.PhoneWindow$DecorView.superDispatchTouchEvent(PhoneWindow.java:1659) 04-11 01:11:11.667: ERROR/AndroidRuntime(1622): at com.android.internal.policy.impl.PhoneWindow.superDispatchTouchEvent(PhoneWindow.java:1107) 04-11 01:11:11.667: ERROR/AndroidRuntime(1622): at com.android.wallpaper.livepicker.LiveWallpaperPreview.dispatchTouchEvent(LiveWallpaperPreview.java:199) 04-11 01:11:11.667: ERROR/AndroidRuntime(1622): at com.android.internal.policy.impl.PhoneWindow$DecorView.dispatchTouchEvent(PhoneWindow.java:1643) 04-11 01:11:11.667: ERROR/AndroidRuntime(1622): at android.view.ViewRoot.handleMessage(ViewRoot.java:1691) 04-11 01:11:11.667: ERROR/AndroidRuntime(1622): at android.os.Handler.dispatchMessage(Handler.java:99) 04-11 01:11:11.667: ERROR/AndroidRuntime(1622): at android.os.Looper.loop(Looper.java:123) 04-11 01:11:11.667: ERROR/AndroidRuntime(1622): at android.app.ActivityThread.main(ActivityThread.java:4363) 04-11 01:11:11.667: ERROR/AndroidRuntime(1622): at java.lang.reflect.Method.invokeNative(Native Method) 04-11 01:11:11.667: ERROR/AndroidRuntime(1622): at java.lang.reflect.Method.invoke(Method.java:521) 04-11 01:11:11.667: ERROR/AndroidRuntime(1622): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:860) 04-11 01:11:11.667: ERROR/AndroidRuntime(1622): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:618) 04-11 01:11:11.667: ERROR/AndroidRuntime(1622): at dalvik.system.NativeStart.main(Native Method) 04-11 01:11:11.667: ERROR/AndroidRuntime(1622): Caused by: java.lang.reflect.InvocationTargetException 04-11 01:11:11.667: ERROR/AndroidRuntime(1622): at com.android.wallpaper.livepicker.LiveWallpaperPreview.configureLiveWallpaper(LiveWallpaperPreview.java:113) 04-11 01:11:11.667: ERROR/AndroidRuntime(1622): at java.lang.reflect.Method.invokeNative(Native Method) 04-11 01:11:11.667: ERROR/AndroidRuntime(1622): at java.lang.reflect.Method.invoke(Method.java:521) 04-11 01:11:11.667: ERROR/AndroidRuntime(1622): at android.view.View$1.onClick(View.java:2026) 04-11 01:11:11.667: ERROR/AndroidRuntime(1622): ... 20 more 04-11 01:11:11.667: ERROR/AndroidRuntime(1622): Caused by: android.content.ActivityNotFoundException: Unable to find explicit activity class {com.ptwallpapers.mywallpaper/MySettingsActivity}; have you declared this activity in your AndroidManifest.xml? 04-11 01:11:11.667: ERROR/AndroidRuntime(1622): at android.app.Instrumentation.checkStartActivityResult(Instrumentation.java:1404) 04-11 01:11:11.667: ERROR/AndroidRuntime(1622): at android.app.Instrumentation.execStartActivity(Instrumentation.java:1378) 04-11 01:11:11.667: ERROR/AndroidRuntime(1622): at android.app.Activity.startActivityForResult(Activity.java:2749) 04-11 01:11:11.667: ERROR/AndroidRuntime(1622): at android.app.Activity.startActivity(Activity.java:2855) 04-11 01:11:11.667: ERROR/AndroidRuntime(1622): ... 24 more 04-11 01:11:11.748: INFO/Process(57): Sending signal. PID: 1622 SIG: 3 04-11 01:11:11.748: INFO/dalvikvm(1622): threadid=7: reacting to signal 3 04-11 01:11:11.827: INFO/dalvikvm(1622): Wrote stack trace to '/data/anr/traces.txt' 04-11 01:11:11.858: ERROR/ActivityThread(57): Failed to find provider info for android.server.checkin 04-11 01:11:11.877: ERROR/Checkin(57): Error reporting crash: java.lang.IllegalArgumentException: Unknown URL content://android.server.checkin/crashes 04-11 01:11:13.788: DEBUG/dalvikvm(101): GC freed 3389 objects / 203632 bytes in 2805ms 04-11 01:11:16.787: INFO/Process(1622): Sending signal. PID: 1622 SIG: 9 04-11 01:11:17.037: INFO/ActivityManager(57): Process android.process.acore (pid 1622) has died. 04-11 01:11:17.046: INFO/WindowManager(57): WIN DEATH: Window{44db47b0 Media:com.android.wallpaper.livepicker/com.android.wallpaper.livepicker.LiveWallpaperPreview paused=false} 04-11 01:11:17.107: INFO/WindowManager(57): WIN DEATH: Window{44db7138 com.android.wallpaper.livepicker/com.android.wallpaper.livepicker.LiveWallpaperListActivity paused=false} 04-11 01:11:17.208: INFO/WindowManager(57): WIN DEATH: Window{44da6860 com.android.wallpaper.livepicker/com.android.wallpaper.livepicker.LiveWallpaperPreview paused=false} 04-11 01:11:17.426: INFO/ActivityManager(57): Start proc android.process.acore for activity com.android.wallpaper.livepicker/.LiveWallpaperListActivity: pid=1647 uid=10022 gids={} 04-11 01:11:18.266: DEBUG/dalvikvm(30): GC freed 222 objects / 8512 bytes in 799ms 04-11 01:11:18.577: DEBUG/ddm-heap(1647): Got feature list request 04-11 01:11:18.686: DEBUG/dalvikvm(30): GC freed 2 objects / 56 bytes in 406ms 04-11 01:11:19.037: INFO/UsageStats(57): Unexpected resume of com.android.wallpaper.livepicker while already resumed in com.android.wallpaper.livepicker 04-11 01:11:19.367: DEBUG/dalvikvm(30): GC freed 2 objects / 56 bytes in 652ms 04-11 01:11:19.827: WARN/ResourceType(1647): getEntry failing because entryIndex 2 is beyond type entryCount 2 04-11 01:11:19.837: WARN/ResourceType(1647): Failure getting entry for 0x7f040002 (t=3 e=2) in package 0: 0x80000001 04-11 01:11:20.378: WARN/InputManagerService(57): Got RemoteException sending setActive(false) notification to pid 1622 uid 10022 04-11 01:11:20.737: INFO/ActivityManager(57): Displayed activity com.android.wallpaper.livepicker/.LiveWallpaperListActivity: 3496 ms (total 3496 ms) 04-11 01:11:21.117: ERROR/gralloc(57): [unregister] handle 0x448168 still locked (state=40000001) 04-11 01:23:24.496: DEBUG/dalvikvm(98): GC freed 12398 objects / 575024 bytes in 213ms

--------------解决方案-------------

弄清楚了。 这是所引用的清单,在服务标签中的元数据标签下的墙纸XML。 基本上,XML已经

<wallpaper
xmlns:android="http://schemas.android.com/apk/res/android"
android:settingsActivity="MySettingsActivity"/>

请注意“MySettingsActivity”呢? 是啊,因为这是从清单单独的文件,它不会自动有一个包就开始从搜索类名。 因此,所有我所要做的就是把完整的包路径,像这样

<wallpaper
xmlns:android="http://schemas.android.com/apk/res/android"
android:settingsActivity="com.ptwallpapers.mywallpaper.MySettingsActivity" />

瞧! 我的选择屏幕上弹出现在,当我打的设置...按钮,而不是武力崩溃。 哦,facepalm!

我想补充一个前导点上你android:name属性(例如, android:name=".MySettingsActivity"或完全限定他们的包(如, android:name="com.ptwallpapers.mywallpaper.MySettingsActivity"

另外,我想摆脱对import com.ptwallpapers.mywallpaper.R因为它应该没有必要(你已经在这个包),并可能会被屏蔽包问题。

如果没有这些帮助,请更新您的问题说明在何处,究竟,你所得到的ActivityNotFoundExceptions

第一个答案,即增加

是对的。 这应该被加入到其中描述的标记xml文件。

如果你想摆脱的设置崩溃删除了android:从同一文件settingActivity标签。

ñNJY的动态壁纸的美丽..

欢呼声,SHIVAM Sabhlok,印度

确保你的MySettingsActivitycom.ptwallpapers.mywallpaper包,否则,您必须指定绝对包的名称。

分类:机器人 时间:2012-06-27 人气:0
分享到:

相关文章

Copyright (C) 55228885.com, All Rights Reserved.

55228885 版权所有 京ICP备15002868号

processed in 0.400 (s). 10 q(s)