我正在制作小部件,它将由 Intent.ACTION_TIME_TICK 更新。
所以我注册了接收者(我的 AppWidgetProvider):
private IntentFilter intentFilter = new IntentFilter(Intent.ACTION_TIME_TICK);
@Override
public void onEnabled(Context context) {
super.onEnabled(context);
context.getApplicationContext().registerReceiver(this, intentFilter);
}
一切正常。但是当我尝试注销接收者时,应用程序崩溃:
@Override
public void onDisabled(Context context) {
context.getApplicationContext().unregisterReceiver(this);
super.onDisabled(context);
}
它抛出
java.lang.IllegalArgumentException: Receiver not registered:
com.holoware.holoclock.HoloClockWidgetProvider@41a3a3e8
日志:
D/AndroidRuntime( 3937): Shutting down VM
W/dalvikvm( 3937): threadid=1: thread exiting with uncaught exception (group=0x4
19e8300)
E/AndroidRuntime( 3937): FATAL EXCEPTION: main
E/AndroidRuntime( 3937): java.lang.RuntimeException: Unable to start receiver co
m.holoware.holoclock.HoloClockWidgetProvider: java.lang.IllegalArgumentException
: Receiver not registered: com.holoware.holoclock.HoloClockWidgetProvider@41d616
20
E/AndroidRuntime( 3937): at android.app.ActivityThread.handleReceiver(Act
ivityThread.java:2362)
E/AndroidRuntime( 3937): at android.app.ActivityThread.access$1500(Activi
tyThread.java:142)
E/AndroidRuntime( 3937): at android.app.ActivityThread$H.handleMessage(Ac
tivityThread.java:1284)
E/AndroidRuntime( 3937): at android.os.Handler.dispatchMessage(Handler.ja
va:99)
E/AndroidRuntime( 3937): at android.os.Looper.loop(Looper.java:137)
E/AndroidRuntime( 3937): at android.app.ActivityThread.main(ActivityThrea
d.java:4931)
E/AndroidRuntime( 3937): at java.lang.reflect.Method.invokeNative(Native
Method)
E/AndroidRuntime( 3937): at java.lang.reflect.Method.invoke(Method.java:5
11)
E/AndroidRuntime( 3937): at com.android.internal.os.ZygoteInit$MethodAndA
rgsCaller.run(ZygoteInit.java:791)
E/AndroidRuntime( 3937): at com.android.internal.os.ZygoteInit.main(Zygot
eInit.java:558)
E/AndroidRuntime( 3937): at dalvik.system.NativeStart.main(Native Method)
E/AndroidRuntime( 3937): Caused by: java.lang.IllegalArgumentException: Receiver
not registered: com.holoware.holoclock.HoloClockWidgetProvider@41d61620
E/AndroidRuntime( 3937): at android.app.LoadedApk.forgetReceiverDispatche
r(LoadedApk.java:654)
E/AndroidRuntime( 3937): at android.app.ContextImpl.unregisterReceiver(Co
ntextImpl.java:1166)
E/AndroidRuntime( 3937): at android.content.ContextWrapper.unregisterRece
iver(ContextWrapper.java:378)
E/AndroidRuntime( 3937): at com.holoware.holoclock.HoloClockWidgetProvide
r.onDisabled(HoloClockWidgetProvider.java:53)
E/AndroidRuntime( 3937): at android.appwidget.AppWidgetProvider.onReceive
(AppWidgetProvider.java:91)
E/AndroidRuntime( 3937): at com.holoware.holoclock.HoloClockWidgetProvide
r.onReceive(HoloClockWidgetProvider.java:63)
E/AndroidRuntime( 3937): at android.app.ActivityThread.handleReceiver(Act
ivityThread.java:2355)
E/AndroidRuntime( 3937): ... 10 more