2017-06-06 6 views
0

私は繰り返しアラームを設定するアプリケーションで作業しています。他のアプリケーションの実行中に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; 

} 
+0

あなたはどのAndroid搭載版を使用していますか? –

+0

ロリポップAPI 22 – Mostafa

答えて

0

AlarmManager docsから:

注:API 19のように、全繰り返しアラームが不正確です。アプリケーションで正確な配信時間が必要な場合は、前述のように毎回リスケジュールする1回限りの正確なアラームを使用する必要があります。 targetSdkVersionがAPI 19より前のレガシーアプリケーションは、繰り返しアラームを含むすべてのアラームを引き続き保持します。

これらの不正確なアラームが発生している可能性があります。

また、アラームが鳴ったときにデバイスを起動させる場合は、RTC_WAKEUPが必要です。

関連する問題