what recommended approach checking new data regardless if app in foreground or background? wondering android api people typically using this. there seems few ways achieve goal, , want make sure i'm on right path.
i have put uses alarmmanager.setinexactrepeating()
call intentservice
sync , inserts/updates data in database. works while app in foreground , background, if force stop app keep seeing "unfortunately, has stopped working" messages when alarmmanager alarm would've triggered. in case, care checking new data when app running in foreground or background.
my first thought detect when app force closed, , stop alarm, not seem possible. asking here, approach wrong? if so, approach used perform periodic task regardless if phone in foreground or background? problem alarmmanager solution using alarms continue fire when app closed.
if idea check if api has new data , perform background sync local database or other data storage, think take @ this:
the sync adapter recommended way of achieving in android. pros of using multiple:
- optimisations out of box - os bundles calls, uses appropriate windows run sync adapter @ minimal bandwidth , battery cost
- the lifecycle of background sync component managed internally os
- observers can notified when data has been changed ui can updated easily
- multiple ways of running sync - @ intervals, automatically os message keep tcp/ip connections open or on demand
however, implementing requires things, can cause bit of pain @ first:
- it mandatory adapter works
contentprovider
- sync adapters use account authentication. if not needed, stub has provided
Comments
Post a Comment