Android Service With Mediaplayer Destroyed When App Detached From Widow
Solution 1:
You need to specify that the service runs in its own process in your app manifest, by adding the attribute android:process=":whatever"
to the service tag. This will ensure that the service isn't killed when your app's main process is, i.e. when the app is removed from the apps list.
If you want to make a service run until the user wants to stop, start it as a foreground service. You do this by calling startForeground
in the service at some point. You need to pass a notification id (integer of your own choosing) and a Notification to startForeground. The notification will stay in the task bar until the user stops the service. You should, of course, provide a PendingIntent to stop the service in the notification or in one of the notification's actions.
Post a Comment for "Android Service With Mediaplayer Destroyed When App Detached From Widow"