###前提・実現したいこと
AlarmManagerを使って定期処理を行いたいです。
###わからないこと
java
1Intent it = new Intent(context, MonitorService.class); 2 int requestCode = 1; 3 PendingIntent pendingIntent = PendingIntent.getService 4 (context, requestCode, it, PendingIntent.FLAG_CANCEL_CURRENT); 5 6 AlarmManager manager = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE); 7 manager.setRepeating(AlarmManager.ELAPSED_REALTIME_WAKEUP, 8 SystemClock.elapsedRealtime(), 3 * 1000, pendingIntent); 9
として3秒ごとにリピートするAlarmManagerからServiceを開始した場合は
Service内で自身をstop();しないと多重起動してしまいますか?
それともFLAG_CANCEL_CURRENTを引数にしていると多重起動はしませんか?
また、3秒ごとにリピートする際にService側の処理が時間がかかってしまった場合に、
Service側の処理を中断して新しくServiceを開始したくないので
AlarmManagerを.setRepeating()する際に「Service内の処理が終わっていたら・・」という処理を実現するためにはどうすればいいでしょうか?
###Service側class
java
1 @Override 2 public int onStartCommand(Intent intent, int flags, int startId) { 3 try { 4 5 6一連の処理・・・・・・・・・・・ 7 8 9 return START_NOT_STICKY; 10 } 11 } 12
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。