开发者

App Widget onUpdate not called when onReceive method exists

开发者 https://www.devze.com 2023-01-29 06:25 出处:网络
I have the following code in my AppWidgetProvider class. @Override public void onUpdate(Context context, AppWidgetM开发者_运维问答anager appWidgetManager, int[] appWidgetIds) {

I have the following code in my AppWidgetProvider class.

@Override
public void onUpdate(Context context, AppWidgetM开发者_运维问答anager appWidgetManager, int[] appWidgetIds) {
    Log.i("Custom", "Update");
}

@Override
public void onReceive(Context context, Intent intent) {
    Log.i("Custom", "Recieve");
}

If I comment out the onReceive method the onUpdate method will be invoked each time I add the widget to the homescreen, if I do not it does not run. Any thoughts?


Try:

@Override
public void onUpdate(Context context, AppWidgetManager appWidgetManager, int[] appWidgetIds) {
    Log.i("Custom", "Update");
}

@Override
public void onReceive(Context context, Intent intent) {
    super.onReceive(context, intent);
    Log.i("Custom", "Recieve");
}

If you take a look at the AppWidgetProvider code, you will see that it invokes the onUpdate method. So, you must call the default onUpdate method of the super class.

0

精彩评论

暂无评论...
验证码 换一张
取 消