-1

I'm currently designing an application on the Android platform, and i need to implement a background service (for notifications ) that will run as long as the device is on but i don't know if the approach i'm about to use is performance friendly.

This is a brief algorithm showing what i'm planning to do:

while(NOTIFICATION_RUN)
{
  if(!isNetworkOn())
    Sleep(60000);//sleep for one minute 
  checkForNotifications();
  Sleep(1000);//in milliseconds
}

the checkForNotifications scenario will look like that:

  1. -Connecting to server
  2. -Getting response
  3. -Processing Response in case of success (show Push Notification on the Android device)

Imagine this code running over and over while your device is on, how would it affect the performance ? Network usage seems low, but what about battery life for the long term ?

  • 1
    How important are these notifications? Do you really need to be checking for them every second? Edit: Also, is this how other apps do it? I thought push notifications (i.e. server to consumer) were a thing now. – Maybe_Factor Feb 28 '18 at 0:04
  • actually the importance varies depending on the notification type but I guess i'll make it Sleep for more than a second – mr.infin8 Feb 28 '18 at 0:06

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Browse other questions tagged or ask your own question.