私はこの状況で助けが必要です:
- IntentServiceを開始するアクティビティがあります。
- サービスは、サイクル中に何らかの仕事をし、しばらくの間眠ります。
- サービスのメインサイクルは無限ですので、再び活動を停止する必要があります。
アクティビティを終了し、再開し、アクティビティの新しい「インスタンス」からIntentServiceを停止できる必要があります。
public class MyService extends IntentService { public MyService() { super("MyService"); } public MyService(String name) { super(name); } @Override protected void onHandleIntent(Intent intent) { Log.d("SERVICE", "start"); while(true) { SystemClock.sleep(1000); Log.d("SERVICE", "tick"); } } @Override public void onDestroy() { Log.d("SERVICE", "end"); super.onDestroy(); }
..。
Intent intent = new Intent(getApplicationContext(), MyService.class);
startService(intent);
電話をかけてみましたが、うまくいきstopService()
ません。これを行う方法はありますか?前もって感謝します。