IntentService 在构建他之后没有保存我的 object
IntentService doesn't save my object after building him
我遇到了一个奇怪的情况,我在方法 onHandleIntent 中将 return 构建为 null,但我不知道为什么或如何解决它。
我的活动
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
// the bluetooth is mentioned in case you know a way to use it with out transfer it from the activity
BluetoothManager _bluetooth_manager = (BluetoothManager)getSystemService(Context.BLUETOOTH_SERVICE);
myService = new MyService(new MyClass(_bluetooth_manager.getAdapter()));
Intent intent = new Intent(this, MyService.class);
startService(intent);
}
我的服务
private MyClass X;
public MyService(MyClass x) {
super("man"); //not so much in the movie... =p
X = x;
}
@Override
protected void onHandleIntent(Intent intent) {
// somehow X is null here after i set him in the constractor. any idea why?
}
如果有人可以编辑我的标题,我不确定我写的好不好理解...谢谢!
永远不会使用该构造函数。您的 IntentService
在其他地方有一个零参数 MyService
构造函数 — 这将是 Android 用来创建您的服务实例的构造函数。
我遇到了一个奇怪的情况,我在方法 onHandleIntent 中将 return 构建为 null,但我不知道为什么或如何解决它。
我的活动
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
// the bluetooth is mentioned in case you know a way to use it with out transfer it from the activity
BluetoothManager _bluetooth_manager = (BluetoothManager)getSystemService(Context.BLUETOOTH_SERVICE);
myService = new MyService(new MyClass(_bluetooth_manager.getAdapter()));
Intent intent = new Intent(this, MyService.class);
startService(intent);
}
我的服务
private MyClass X;
public MyService(MyClass x) {
super("man"); //not so much in the movie... =p
X = x;
}
@Override
protected void onHandleIntent(Intent intent) {
// somehow X is null here after i set him in the constractor. any idea why?
}
如果有人可以编辑我的标题,我不确定我写的好不好理解...谢谢!
永远不会使用该构造函数。您的 IntentService
在其他地方有一个零参数 MyService
构造函数 — 这将是 Android 用来创建您的服务实例的构造函数。