[英]How to make an activity always run in background
I am making an application in which i am using broadcast reciever to call a service. 我正在制作一个使用广播接收器来调用服务的应用程序。 The problem is that I have to open the application to make the service work.
问题是我必须打开应用程序才能使服务正常工作。 I want that just install application and it will run the service automatically.
我只想安装应用程序,它将自动运行服务。
In the main activity I have used Intent filter and I have made a class for brodcast reciever and called onRecieve method 在主要活动中,我使用了Intent过滤器,并为广播接收器创建了一个类,并调用了onRecieve方法
If you want to run something in background it should be a Service . 如果您想在后台运行某些程序,则应该将其作为Service 。 It was designed specifically for this purpose.
它是专门为此目的而设计的。 The sole purpose of an Activity is user interaction .
一个活动的唯一目的是用户交互 。
您可以在服务中使用startforeground()
方法来避免被杀死。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.