Most of you must have used "whatsapp" and "viber". These apps constantly keep running even when they are exited. I want one of my activities to keep running in the background after its being ran for the first time. And I also want the whole app to keep running in the background like viber and whatsapp do. How can I do that?
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试):
问题:
This question already has answers here:
Closed 6 years ago.
回答1:
Use service
. Read this and this about details of service.
You can keep your activity running in the background. But I think it is definitely a better idea to keep a service running in the background. You will get a basic idea about the service by reading above two links.
回答2:
It's not the Activity
that keeps running in the background but a Service
. Look at http://developer.android.com/reference/android/app/Service.html for implementing it.