I am attempting to make a call to a service, and based on the response, redirect the user to a different activity (a login).
If I wait to do this until say, a button click, then it works fine (since the service is bound), but if I do it onResume, then I get the following exception:
ERROR/AndroidRuntime(2226): FATAL EXCEPTION: main
java.lang.RuntimeException: Unable to resume activity {...MyActivity}:
java.lang.NullPointerException
and my code is:
FooService fooService;
@Override
protected void onStart() {
super.onStart();
Intent intent = new Intent(this, FooService.class);
bindService(intent, fooServiceConnection, Context.BIND_AUTO_CREATE);
}
@Override
protected void onResume() {
//I would assume the service would have bound by now?
super.onResume();
doSomething();
}
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…