Is remote services used by other applications in Android?
If I create a remote service in my app then will 开发者_运维问答it accessible to other apps too. I want that it should not be accessible to other apps. But I need to create a remote service since it needs to keep running in the background.
If I create a remote service in my app then will it accessible to other apps too.
Yes. That is the point behind having a remote service.
I want that it should not be accessible to other apps.
Then do not make a remote service.
But I need to create a remote service since it needs to keep running in the background.
A remote service will not "keep running in the background", any more than a local service will "keep running in the background". You cannot write a service that will "keep running in the background" very long. That is because developers have tried writing services that "keep running in the background", causing problems for users. Users have responded with task killers, and the Android OS has responded by terminating services that run too long.
If your service is part of the foreground user experience (e.g., a music player), use startForeground()
and a Notification
to minimize the odds of your service being terminated.
Otherwise, please redesign your application to not require a service that will "keep running in the background". For example, to do some work every 15 minutes, use AlarmManager
and an IntentService
.
精彩评论