我在我的 BootReceiver 类中收到一个启动完成的意图,并在我收到该意图时启动一项服务。
@Override
public void onReceive(Context arg0, Intent arg1) {
Intent myIntent = new Intent(arg0, BootService.class);
arg0.startService(myIntent);
}
该服务已正常启动,现在我想在服务中使用 binder 对象。这是服务代码。
public class BootService extends Service implements IBinder{
private IBinder binder;
public class LocalBinder extends Binder {
IBinder getService() {
return BootService.this;
}
}
@Override
public void onCreate() {
super.onCreate();
Log.d("BootService", "onCreate()");
}
@Override
public int onStartCommand(Intent intent, int flags, int startId) {
Log.d("BootService", "onStartCommand()");
binder = new LocalBinder().getService();
//This doesn't seem to work
//I wana use this binder object here
return START_STICKY;
}
.....
}
我不确定这是否是获得活页夹的正确方法。任何帮助深表感谢!!