i currently play around a little bit with Game development on Android and want to implement a small idle game. My current implementation uses an AlarmManager, which triggers an IntentService (GameService) every X seconds. The complete work (increasing progress for different items etc) is done in the GameService which runs in the Worker-Thread of the IntentService. Therefor I don't have any UI-Blocking issues. The work performed by the GameService is not that CPU intense (reading data from DB, increasing some fields and saving it again).
But I experienced several battery usage issues with this kind of service (most likely cause it wakes up the device/cpu on each run). So I currently try to figure out a better way to have a GameService running in Background.
My first approach was to detect the screen-off/on events and increase/decrease the interval (1 second if screen is on, 30 seconds if screen is off), but this only helped marginal.
Now my next step is to calculate the target time when the user has to be notified (resource X empty or something like this) and stop the complete Service till this time. This will most likely make the GameService more battery sparing.
But all of those measures only deal with changing the GameService and don't challenge the concept of having a IntentService triggered by an AlarmManager.
Therefor I currently try to find alternative ideas for having the service run in background if required.
One more problem arises from http://ift.tt/1BmOkXs which means, I can no longer use a 1-second interval in my AlarmManager as the System will increase the time to 60 seconds on Android 5.1.
I'd be happy to get your feedback!!
Regards and thank you for your time!
Aucun commentaire:
Enregistrer un commentaire