私は繰り返しアラームを設定するアプリケーションで作業しています。他のアプリケーションの実行中にAlarmManagerの間隔が変更される
私のサービスの1つを2分ごとに実行することになっています。 myApplicationアクティビティを実行しても正常に動作しますが、他のアプリケーションがフォアグラウンドで実行されている場合、間隔は5分になります!!!
私はこのコードをフォアグラウンドで開始している別のサービスの中で実行します。
なぜこのようなことが起こっているのかわかりません。
public class Serv1 extends Service{
public static Intent intentServ2 = new Intent(G.context,Serv2.class);
public static PendingIntent pendingIntend=PendingIntent.getService(G.context,0,intentServ2,0);
public static AlarmManager alarmManager;
public int onStartCommand(Intent intent, int flags, int startId) {
alarmManager =(AlarmManager) getSystemService(ALARM_SERVICE);
alarmManager.setRepeating(AlarmManager.RTC, System.currentTimeMillis()+(2*1000),120*1000,pendingIntend);
Intent notificationIntent = new Intent(this, Serv1.class);
PendingIntent pendingIntent = PendingIntent.getService(this, 0,
notificationIntent, 0);
Notification notification = new NotificationCompat.Builder(this)
.setSmallIcon(R.mipmap.ic_launcher)
.setContentTitle("Serive1")
.setContentText("Service is working...")
.setContentIntent(pendingIntent).build();
startForeground(254698, notification);
return Service.START_STICKY;
}
あなたはどのAndroid搭載版を使用していますか? –
ロリポップAPI 22 – Mostafa