public class LocationActivity extends Activity { //一个Activity传值到service
public static String workid = null;
protected void onStart() {
LocationActivity.workid = new SimpleDateFormat("MMddHHmm").format(date);
Intent idintent = new Intent(LocationActivity.this, MyLocationService.class);
idintent.putExtra("workid", LocationActivity.workid);
startService(idintent);
}
}
public class MyLocationService extends Service { //一个Service
public static String workid; //声明一个static变量,在Service类加载时创建。
public void onStart(Intent intent, int startid) { //onstart方法
MyLocationService.workid = intent.getStringExtra("workid"); //直接用类名+"."调用static型变量
}
}