AppWidgetProvider: the onEnabled method is not called

I have a widget displaying data from a content provider. I want to know when the data in the content provider changes. As far as I know, the way to do this is

context.getContentResolver().registerContentObserver

But the AppWidgetProvider.onEnabled method is not called when I add the first instance of the widget. That is why I can not do registerContentObserver. Same thing with onDisabled.

How to solve this problem?

thank

+1
source share
2 answers

You need to add android.appwidget.action.APPWIDGET_ENABLED as another action:

<intent-filter>
    <action android:name="android.appwidget.action.APPWIDGET_UPDATE" />
    <action android:name="android.appwidget.action.APPWIDGET_ENABLED" />
    <action android:name="android.appwidget.action.APPWIDGET_DELETED" />
    <action android:name="android.appwidget.action.APPWIDGET_DISABLED" />  
</intent-filter>

Without this, you will not receive a broadcast that runs onEnabled ().

: APPWIDGET_DELETED onDeleted (...),     APPWIDGET_DISABLED onDisabled (...)

+5

An AppWidgetProvider ( BroadcastReceiver) registerContentObserver(). , , - (, android:updatePeriodMillis).

+3

Source: https://habr.com/ru/post/1532076/


All Articles