在activity中: Intent service=new Intent(CarActivity.this, GetLocation.class);// 设置服务将要跳转
service.putExtra("CAR_ID", userid);// 将userid传递给CAR_ID在service中: public void onStart(Intent intent, int startId) {
// TODO Auto-generated method stub
super.onStart(intent, startId);
carID= intent.getStringExtra("CAR_ID");
System.out.println("Get args from intent:" + carID); }这样,在logcat中能正常输出,但是,如果将System.out.println("Get args from intent:" + carID);放在其他地方,打印Get args from intent: null
大侠们帮忙啊。。
service.putExtra("CAR_ID", userid);// 将userid传递给CAR_ID在service中: public void onStart(Intent intent, int startId) {
// TODO Auto-generated method stub
super.onStart(intent, startId);
carID= intent.getStringExtra("CAR_ID");
System.out.println("Get args from intent:" + carID); }这样,在logcat中能正常输出,但是,如果将System.out.println("Get args from intent:" + carID);放在其他地方,打印Get args from intent: null
大侠们帮忙啊。。
你是不是在onCreate,或者onCreate调用的函数理使用了这个全局变量?
onCreate是在onStart之前运行的,如果是这样,你取不到变量很正常。