所以我正在修改 Cube 动态壁纸示例。我有一个扩展 PreferenceActivity 的类,我在清单文件中添加了 Activity。我不断收到 ActivityNotFoundExceptions。
这是我的偏好类:
package com.p.t.wallpapers.mywallpaper;
import com.p.t.wallpapers.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.p.t.wallpapers.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.p.t.wallpapers.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.p.t.wallpapers.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: com.android.internal.view.IInputMethodClient$Stub$Proxy@44db02f8
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.p.t.wallpapers.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.p.t.wallpapers.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