如何运行后台服务中的active worker?
How to run active worker in background service?
我有一个 Worker Thread class extends Thread 并且我在队列中添加工人 class.I 想要 运行 一个工人背景 service.This 是我的服务和 onStartCommand 方法
protected WorkerThread workerThread;
@Override
public int onStartCommand(Intent intent, int flags, int startId) {
if (this.looperThread.isAlive()) {
this.looperThread.start(); }
return Service.START_STICKY;
}
我在我的 MainActivity 中启动服务,但我关闭了应用程序我得到了这样的错误 looperThread.start() 空点异常。我怎么能运行 后台服务人员?谢谢
您需要意向服务。你可以把你想要的所有代码放在它里面的工作线程中。这是一个例子
public class MyService extends IntentService {
public MyService() {
super("Cashback IntentService");
}
@Override
protected void onHandleIntent(Intent intent) {
....Your code that is to be executed in background goes here
}
}
我有一个 Worker Thread class extends Thread 并且我在队列中添加工人 class.I 想要 运行 一个工人背景 service.This 是我的服务和 onStartCommand 方法
protected WorkerThread workerThread;
@Override
public int onStartCommand(Intent intent, int flags, int startId) {
if (this.looperThread.isAlive()) {
this.looperThread.start(); }
return Service.START_STICKY;
}
我在我的 MainActivity 中启动服务,但我关闭了应用程序我得到了这样的错误 looperThread.start() 空点异常。我怎么能运行 后台服务人员?谢谢
您需要意向服务。你可以把你想要的所有代码放在它里面的工作线程中。这是一个例子
public class MyService extends IntentService {
public MyService() {
super("Cashback IntentService");
}
@Override
protected void onHandleIntent(Intent intent) {
....Your code that is to be executed in background goes here
}
}