IntentService を拡張するクラスは、startService() を呼び出して再び開始できますか?
public class testService extends IntentService{
public testService (String name){
super(name);
}
onHandleIntent(Intent intent){
startService(testService.class); //CAN YOU DO THIS?
}
IntentService を拡張するクラスは、startService() を呼び出して再び開始できますか?
public class testService extends IntentService{
public testService (String name){
super(name);
}
onHandleIntent(Intent intent){
startService(testService.class); //CAN YOU DO THIS?
}
答えは「はい」だと思います。
サービスの開始はすべて、使用しているコンテキストのタイプによって異なります ( http://www.doubleencore.com/2013/06/context/ )
IntentService と通常の Service の唯一の違いは、完了すると自動的にそれ自体を強制終了し、バックグラウンド スレッドを生成して長い操作 (ネットワークなど) を実行できるようにすることです。
答えはイエスです。longpoll 操作にも同じパターンを使用します。システムの観点からは再帰ではないため、スタック オーバーフローは発生しません。ただし、電力を節約するために、しばらくしてから AlarmManager を使用してサービスを再起動することをお勧めします。