Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <blockquote> <p>Will it ever be restarted without rebooting the phone?</p> </blockquote> <p>Possibly. If it truly was because "system kills it for memory", and you return an appropriate value from <code>onStartCommand()</code> (e.g., <code>START_STICKY</code>), it should be restarted at some point in the future. If the service was killed due to user action (e.g., Force Stop in the Manage Services screen in Settings), it will not be restarted.</p> <blockquote> <p>What is the best practice to avoid as much as possible an important service from being killed?</p> </blockquote> <p>First, design your application to not rely on an everlasting service like this. 99.44% of Android applications do not need a service that runs continuously, let alone one that starts doing so at boot time. Android device users hate developers who think that their apps are sooooooooooooo important that they have services running all the time -- that's why we have task killers, Force Stop, and Android killing services due to old age. For example, if you are checking for new email every 15 minutes, use <code>AlarmManager</code> and an <code>IntentService</code>, not a service that runs forever.</p> <p>If you can demonstrate -- to me and to your users -- that yours is among the 0.56% of applications that really do need a service that starts at boot time and runs forever, you can use <code>startForeground()</code>. This will indicate to the OS that your service is part of the foreground user experience. You will have to display a <code>Notification</code>, ideally to allow the user to shut down your service cleanly if and when the user no longer feels that it is justified.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload