运行代码后我遇到start service
问题。
我的服务类:
@Override
public int onStartCommand(Intent intent, int flags, int startId) {
super.onStartCommand(intent, flags, startId);
mApplication.setService(this);
}
现在:
startService(intent); // service run sucess, but after millisecond delay
mApplication.setIsServiceRunning(true);
mApplication.getService().MyMethodAnyThing(); // <--- NullPointerExeption, because in my class mApplication.setService(this) do with delay and getService is null.
我需要completed start service
。例如:
startService(intent);
mApplication.setIsServiceRunning(true);
// i need like listener
@Override
onServiceIsRunComplete() {
// here i'm sure that service is run
mApplication.getService().MyMethodAnyThing();
}
答案 0 :(得分:1)
也许是这样的,
(member 1.0 '(3 2.0 1) :test #'=) ; numeric
(member "fOo" '("foo" "FOO" "fOo") :test #'string=) ; case-sensitive
(member "foo" '("FOO" "BAR" "QUUX") :test #'string-equal) ; case-insensitive
停止服务时也不要忘记unbindService()。