android 在service中用onStart()获取activity传递的值,能接受到这个值,但是不能应用于全局变量呢?解决方法
android 在service中用onStart()获取activity传递的值,能接受到这个值,但是不能应用于全局变量呢?
在activity中:
在service中:
这样,在logcat中能正常输出,但是,如果将System.out.println("Get args from intent:" + carID);放在其他地方,打印Get args from intent: null
大侠们帮忙啊。。。。。
------解决方案--------------------
请说清楚点。
------解决方案--------------------
不影响你使用不就行了吗
------解决方案--------------------
在activity中:
- Java code
Intent service=new Intent(CarActivity.this, GetLocation.class);// 设置服务将要跳转 service.putExtra("CAR_ID", userid);// 将userid传递给CAR_ID
在service中:
- Java code
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
大侠们帮忙啊。。。。。
------解决方案--------------------
请说清楚点。
------解决方案--------------------
不影响你使用不就行了吗
------解决方案--------------------