チェックボックスのあるアクティビティがあります。チェックボックスがオフになっている場合は、サービスを停止してください。これは私のアクティビティコードのスニペットです:
Intent serviceIntent = new Intent();
serviceIntent.setAction("com.android.savebattery.SaveBatteryService");
if (*unchecked*){
serviceIntent.putExtra("user_stop", true);
stopService(serviceIntent);
サービスを停止するときは、パラメータ「user_stop」を渡して、システムではなくユーザーがサービスを停止したことを示します(メモリ不足の場合)。
ここで、サービスのvoidonDestroyにある変数「user_stop」を読み取る必要があります。
public void onDestroy() {
super.onDestroy();
Intent recievedIntent = getIntent();
boolean userStop= recievedIntent.getBooleanExtra("user_stop");
if (userStop) {
*** notification code ****
しかし、それは機能しません!onDestroyでgetIntent()を使用できません!
なにか提案を?
ありがとう
シモーネ