简体   繁体   English

即使我们在Android中强制应用程序,如何启动服务?

[英]How to start a Service even if we force the application in Android.?

我创建了一个Activity并在该Activity中启动了服务。即使我们强制关闭应用程序,该服务也应在后台运行。请帮助我解决此问题。

Services run on the same proccess of its application. 服务在其应用程序的同一进程上运行。 For this, they should die if its application is force closed. 为此,如果强制关闭应用程序,他们应该死亡。

Maybe you should think about using different threads: Processes and Threads 也许您应该考虑使用不同的线程: 进程和线程

When app gets force close then service gets destroyed. 当应用程序强制关闭时,服务将被破坏。 Check out below link, which shows a Return value from onstartCommand func. 请查看下面的链接,该链接显示了onstartCommand函数的返回值。 http://developer.android.com/reference/android/app/Service.html#START_STICKY By this system restarts service. http://developer.android.com/reference/android/app/Service.html#START_STICKY通过此系统重新启动服务。 Check this also. 也检查一下。 http://developer.android.com/reference/android/app/Service.html#START_CONTINUATION_MASK http://developer.android.com/reference/android/app/Service.html#START_REDELIVER_INTENT http://developer.android.com/reference/android/app/Service.html#START_CONTINUATION_MASK http://developer.android.com/reference/android/app/Service.html#START_REDELIVER_INTENT

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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