Reputation: 922
We are working on a little social app, that is supposed to inform the user about likes, comments, new friend requests, etc. with a little push notification on the users phone. So, even when the app is not open at all (like whatsapp for instance), the user is still informed about news in his or her app.
So the problem is, I have almost no clue of how to go on about this a smart way. I used started services but those do not run when an app is closed. How would I go on about this? Any clue would be greatly appreciated!
Thanks :)
Upvotes: 0
Views: 36
Reputation: 7674
If you wish to fetch data from the server every X minutes, you might want to use AlarmManager:
Intent intent = new Intent(this, YourClass.class);
PendingIntent pendingIntent = PendingIntent.getService(this, 0, intent, 0);
AlarmManager alarm = (AlarmManager)getSystemService(Context.ALARM_SERVICE);
alarm.setRepeating(AlarmManager.RTC_WAKEUP, System.currentTimeMillis(),X * 60000, pendingIntent);
Replace X with the number of minutes.
Upvotes: 1