Many of the android applications now a days need to fetch data from server. Apps need to be always updated. If one use GCM then all the worries about when to check for update is gone :D. But if this is not case then there remains a question – who will trigger to check for update. There are several design ways to get this trigger in android.
1. Sync Adapter – It is asynchronous. That means we may not get instant result from syncing. Syncing can happen at any time in the background.
2. Alarm Manager – Use Alarm manger as a trigger to check for update. It is also asynchronous.
3. Android Service – We can make our own service which will check for update periodically. In this case it not better than point#2.
above three will work even if the application is not running.
4. Custom thread and Handler – It is also asynchronous. We can have some extra control over the thread while our application is running.
Using Alarm manager will drain battery, this concept is indefinite for android. Cause if we manage your own thread/service that will also cost us the periodic checking. In this case alarm manager helps us by not checking for update, it is just triggering our application at the time when we want to check for update. So the best is to find the correct way for our project.
For Battery Issue and why one should sync adapters these links may be helpful –
1. http://developer.android.com/…/efficient…/index.html
2. http://developer.android.com/tra…/sync-adapters/index.html
Leave a Reply