在活动中,我已经像这样传递了一个值 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 方法。请告诉我问题出在哪里??