Reputation: 6951
after an extensive search I still can't find a solution to my problem:
I need a Broadcast that runs once a day, no matter if the App is running or not. However, IF the App is running, I also need to update the UI at the end of/after the Broadcast.
I can't use a programmatically registered Broadcast because it ends with the Apps lifecycle. But from a static manifest-registered Broadcast I can't access the UI (at-least I don't know HOW). One option would be to have 2 different Broadcasts and cancel/start them in onPause and onResume, but I wonder if there is an easier solution?
Upvotes: 0
Views: 201
Reputation: 938
The thing you need is not broadcast receiver along with AlarmManager or JobScheduler for api above 21 and greenrobot event bus.
AlarmManager Schedules the broadcast call once a day or at any time you want and every time if the broadcast is called you can trigger event from eventbus and receive that event in the place where you want it. The thing why to use event bus is we do not need to handle if the view is visible or not.iF the view is in re use state it triggers the event the view and one method is called by event bus and in that method you can do anything you want to do with view.
personally i don't prefer service because service execution is really expensive now a days.
Note: the package name where you put alarm manager and broadcast receiver should be "alert" some samsung mobile are very optimized so they will only let the package name with "alert to run fully". You will also need on boot receiver to register receiver and schedule alarmmanager in case if the phone is booted.
Upvotes: 1