【发布时间】:2018-05-24 07:11:19
【问题描述】:
我有一个 Worker Thread 类扩展了 Thread,我在这个类的队列中添加了工作者。我想在后台服务中运行一个工作者。这是我的服务和 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() Null point Exception。如何在后台服务中运行 worker?谢谢
【问题讨论】:
-
试过
android.app.IntentService? -
所以请阅读
IntentService的文档——这是你所需要的
标签: android multithreading service nullpointerexception worker