我有一个带有复选框的活动:如果未选中复选框,则停止服务。这是我的活动代码片段:
Intent serviceIntent = new Intent();
serviceIntent.setAction("com.android.savebattery.SaveBatteryService");
if (*unchecked*){
serviceIntent.putExtra("user_stop", true);
stopService(serviceIntent);
当我停止服务时,我传递一个参数“user_stop”来说明用户停止它而不是系统(内存不足)的服务。
现在我必须在我的服务的 void onDestroy 中读取变量“user_stop”:
public void onDestroy() {
super.onDestroy();
Intent recievedIntent = getIntent();
boolean userStop= recievedIntent.getBooleanExtra("user_stop");
if (userStop) {
*** notification code ****
但它不起作用!我不能在 onDestroy 中使用 getIntent()!
有什么建议吗?
谢谢
西蒙娜