【发布时间】:2012-08-16 08:03:58
【问题描述】:
在 Activity 中,我传递了一个像这样的值 paramVal
Intent srv = new Intent(this, TestService.class);
startService(srv);
//Intent intent =new Intent("com.example.firstapplication.STARTACTIVITY");
//intent.putExtra("myFirstKey", paramVal);
//intent.putExtra("myFirstKey", paramVal);
Bundle bundle = new Bundle();
bundle.putCharSequence("myFirstKey", paramVal);
intent.putExtras(bundle);
在服务中,我正在检索这样的值
@Override
public void onStart(Intent intent, int startId) {
// TODO Auto-generated method stub
super.onStart(intent, startId);
Bundle bundle = intent.getExtras();
data = (String) bundle.getCharSequence("myFirstKey");
System.out.println("data checking"+data);
}
但我得到该行的空指针异常
data = (String) bundle.getCharSequence("myFirstKey");
服务中
我是否必须在某处的服务中调用 onstart 方法。请告诉我问题出在哪里??
【问题讨论】:
-
见android-coding.blogspot.in/2011/03/… tuts 用于将数据从 Activity 传递到 Serivce 以及在您当前的代码中,您在将价值放入意图之前启动服务,因此在准备好意图后启动它
标签: android service android-intent