简体   繁体   中英

Android, C#: How can I make my app constantly check for news in the background?

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 :)

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM