service中总是获取不到context,sendBroadcast报空指针异常
`public class HandleMessage extends Service{
private String qrcontent = null;
private Context context = this;
@Override
public void onCreate() {
super.onCreate();
context = this;
}
public void doSomething(final String content){
qrcontent = content;
new Thread(new Runnable() {
@Override
public void run() {
//发送广播
Intent intent=new Intent();
intent.putExtra("qrcontent", qrcontent);
intent.setAction("com.HandleMessage");
if(intent != null){
LocalBroadcastManager.getInstance(context).sendBroadcast(intent);
}else{
Log.e("---","null intent");
}
}
}).start();
}
}`
服务在哪启动的
为什么开个线程去发广播?