Update Android widget provided

I am just starting out with Android development and have written an application to show details about battery status. Now I wanted to put all this into the widget - and here's the question: Do I really need an update service in the background to listen for ACTION_BATTERY_CHANGED? My first thought was to line the intet-filter tag of the widget in AndroidManifest.xml - but obviously this is not so simple. If UpdateService is the right way, I will do it - but I just wanted to make sure it was the right solution

+3
source share
3 answers

Do I really need a background update service to listen for ACTION_BATTERY_CHANGED intentions?

BroadcastReceiver ACTION_BATTERY_CHANGED. registerReceiver().

, . AlarmManager, (, !). , registerReceiver() ACTION_BATTERY_CHANGED IntentFilter BroadcastReceiver (null ). ACTION_BATTERY_CHANGED Intent, .

+4

, . 30 . updatePeriodMillis AppWidgetProviderInfo

<appwidget-provider
   xmlns:android="http://schemas.android.com/apk/res/android"
   android:updatePeriodMillis="1800000" />

.. , onUpdate AppWidgetProvider.

edit: , 30 - , .

+2

Believe it or not, the following works:

cont.getApplicationContext().registerReceiver(rec, filter);
+1
source

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


All Articles