0
我正试图调用服务,并根据响应将用户重定向到不同的活动(登录名)。在onResume中调用服务时出现NullPointerException
如果我等待做,直到说,点击一个按钮,然后它工作正常(因为服务绑定),但如果我这样做的onResume,然后我得到以下异常:
ERROR/AndroidRuntime(2226): FATAL EXCEPTION: main
java.lang.RuntimeException: Unable to resume activity {...MyActivity}:
java.lang.NullPointerException
我的代码是:
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();
}
@UBM:如果您来自Javascript背景,PhoneGap可能会是您的更好选择。 “它正在做网络I/O ......你能提供一些可以帮助我做到的资源吗?” - 这是一个'IntentService',它接收下载文件的命令,然后将其下载并在下载完成后让活动知道结果:https://github.com/commonsguy/cw-android/tree/主/服务/下载器“,如果我依赖这项服务,在准备好后我怎么能打电话给它?” - 从'onServiceConnected()'调用它。 – CommonsWare 2011-04-24 15:03:18