我遇到了触发AppWidgetReciever的onEnabled和onDisabled方法的问题。我有指定的动作,我还记录了onRecieve方法中的每个动作,但我得到的唯一两个动作是“APPWIDGET_UPDATE”和“APPWIDGET_DELETED”。我已经搜索这个解决方案,但不幸的是没有发现。这里是我的代码:Android onEnabled/onDisabled从未呼吁
清单部分:
<receiver android:name=".ScheduleWidgetProvider" >
<intent-filter>
<action android:name="android.appwidget.action.APPWIDGET_ENABLED" />
<action android:name="android.appwidget.action.APPWIDGET_DISABLED" />
<action android:name="android.appwidget.action.APPWIDGET_UPDATE" />
<action android:name="android.appwidget.action.APPWIDGET_DELETED" />
</intent-filter>
<meta-data android:name="android.appwidget.provider"
android:resource="@xml/provider_xml" />
</receiver>
Provider_xml:
<?xml version="1.0" encoding="utf-8"?>
<appwidget-provider xmlns:android="http://schemas.android.com/apk/res/android"
android:minWidth="180dp"
android:minHeight="40dp"
android:updatePeriodMillis="60000"
android:initialLayout="@layout/widget_layout"
android:configure="org.zivkovic.schedule.ConfigurationActivity"
>
</appwidget-provider>
ScheduleWidgetProvider:
public class ScheduleWidgetProvider extends AppWidgetProvider {
{
Log.w("Schedule", "ScheduleWidgetProviderRequested");
}
@Override
public void onReceive(Context context, Intent intent) {
Log.w("Schedule", "On recieve " + intent.getAction());
super.onReceive(context, intent);
}
@Override
public void onEnabled(Context context) {
Log.w("Schedule", "OnEnabled called");
...
super.onEnabled(context);
}
@Override
public void onDisabled(Context context) {
Log.w("Schedule", "OnDisabled called");
...
super.onDisabled(context);
}
@Override
public void onUpdate(Context context, AppWidgetManager appWidgetManager, int[] appWidgetIds) {
for (int i = 0; i < appWidgetIds.length; i++) {
....
}
super.onUpdate(context, appWidgetManager, appWidgetIds);
}
}
任何帮助表示赞赏。谢谢!
我有一个类似的问题,这对我工作。我敢打赌,小部件与系统更紧密地联系在一起,重新安装不会影响行为。谢谢你的提示! – pkk
也为我工作,谢谢! –
它也适用于我,但为什么?我有这个问题只是**有时**当我安装我的应用程序在'AndroidStudio'的设备上进行测试。我也把所有需要'意图过滤器',但我有时看到这个问题,它需要'卸载'+'重新安装'再次。 – RAM