设备启动后,两次调用Android小部件更新 [英] Android widget update called twice after device boot

查看:108
本文介绍了设备启动后,两次调用Android小部件更新的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

设备重新启动后,我首先收到APPWIDGET_ENABLED,然后收到两次 APPWIDGET_UPDATE. 我花了几个小时来搜索,但没有结果. 有人遇到同样的事情吗?您是否找到避免两次调用此更新的方法?

After device reboot I receive first APPWIDGET_ENABLED and then twice APPWIDGET_UPDATE. I spent quite some hours googling this without result. Is anybody experiencing the same? Have you found a way to avoid calling the update twice?

以下是一些代码:

    <receiver android:name=".Widget" android:label="@string/app_name">
        <intent-filter>
             <action android:name="android.appwidget.action.APPWIDGET_UPDATE" /> 
        </intent-filter>
        <meta-data android:name="android.appwidget.provider" android:resource="@xml/button_widget_provider" />
    </receiver>



public void onReceive(final Context context, final Intent intent) {
    super.onReceive(context, intent);
    final String action = intent.getAction();

    if  (AppWidgetManager.ACTION_APPWIDGET_UPDATE.equals(action) ) {
        Log.i(TAG, "update");
    } else if (AppWidgetManager.ACTION_APPWIDGET_ENABLED.equals(action) ) {
        Log.i(TAG, "enabled");
    }
}

推荐答案

您找到了避免两次调用更新程序的方法吗?

Have you found a way to avoid calling the update twice?

您无法控制更新的次数.这取决于主屏幕和应用程序小部件框架.

You have no control over how many times you are updated. That is up to the home screen and the app widget framework.

这篇关于设备启动后,两次调用Android小部件更新的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆