I am writing an android application, which communicates with server when the user logs in to the application. Now if the user closes the application without logging out, I want to query the server every 15 minutes, to see whether the particular user has received any updates. If yes then, I want to push a notification, on clicking which the user goes straight into the applications activity which shows the update.
How can this be implemented in android? Is it possible?
Can anyone suggest solutions using timer? And please remember this background program should run only when the actual application is closed.
Yes, this is possible.
I would do the following:
Use
AlarmManagerwithsetRepeating. This will get you your 15 minute interval.In
setRepeating, pass in aPendingIntentfor anIntentServicesubclassIn your
IntentServicesubclass, inhandleIntent, query your server then create aNotificationlike documented at http://developer.android.com/guide/topics/ui/notifiers/notifications.htmlThe
Notificationwill contain anotherPendingIntentwhich will bring the user back to your app. Make sure to specify theActivitythat contains the UI that is relevant for that update.You can learn more about IntentServices in the Services Guide at http://developer.android.com/guide/topics/fundamentals/services.html
You can learn more about AlarmManager at http://developer.android.com/reference/android/app/AlarmManager.html