I have an activity which just displays a daily counter. When the day ends, i want to send a notification with last day counter, insert it in a db and if the app is running update the counters label to zero.
I think i must register a static <receiver>android.intent.action.DATE_CHANGED</receiver>
. so as to get notified even if the activity is not running.
There I insert the value in DB and i send the notification.
And a dynamic created broadcast receiver which i will unregister onPause, which receives the same events, but it will only update the UI and specifically the label.
Is this the best solution?
Is there any way from a broadcastReceiver
to make my Activity
(if is running) to go to resume again ?
Is it possible from broadcastReceiver
to call a Service
, which will update my UI if my Activity is running?
After more reading i found that the best solution is the above.
A static broadcast receiver for DATE_CHANGED actions. This will start a Service which will update the db and send a local custom broadcast (com.myBroadcast.WakeUpActivity) The Activity if is running will register a receiver for the previous custom broadcast (will unregister onPause), and will update the UI.
Use broadcastreceiver that would catch the event
broadcastreceiver give event service
then you need to connect to the service in your activity
and do not forget to mention the service and broadcastreceiver in the manifest file and specify the intent filter
You can simply use a LocalBroadcastReceiver to send events to your Activity , a working example could be found here