【问题标题】:App Widget onUpdate not called when onReceive method exists存在 onReceive 方法时未调用 App Widget onUpdate
【发布时间】:2010-12-04 05:20:06
【问题描述】:

我的AppWidgetProvider 类中有以下代码。

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

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

如果我注释掉onReceive 方法,则每次我将小部件添加到主屏幕时都会调用onUpdate 方法,否则它不会运行。有什么想法吗?

【问题讨论】:

    标签: android android-appwidget


    【解决方案1】:

    试试:

    @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");
    }
    

    如果您查看AppWidgetProvider 代码,您会发现它调用了onUpdate 方法。所以,必须调用超类默认的onUpdate方法。

    【讨论】:

    • 谢谢,真的应该自己捡起来!
    猜你喜欢
    • 2013-08-06
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-04-20
    • 1970-01-01
    • 1970-01-01
    • 2011-03-15
    相关资源
    最近更新 更多