2017-09-14 13 views
0

私のアプリには5分ごとに繰り返し実行されるタスクがあります。私は同じアプリを2回インストールしようとすると、Alarm Managerはタスクを実行するためにブロードキャストに起動しません。アラーム管理の問題

初めて同じ方法でインストールしてください。同じバージョンを再インストールするまで、タスクは繰り返されません。これはAlarm Managerの問題です。理解できません。

これは私のコードです:

 Intent intent = new Intent(context, CheckingPriceReceiver.class); 
    intent.setAction("com.abccompany.trading"); 

    PendingIntent pendingIntent = PendingIntent.getBroadcast(context, 
    REQ_CODE, intent, PendingIntent.FLAG_UPDATE_CURRENT); 

    long mInterval = 300000; 
    long triggerTime = System.currentTimeMillis() + mInterval; 

    AlarmManager alarmManager = (AlarmManager) 
    context.getSystemService(Context.ALARM_SERVICE); 

    alarmManager.setRepeating(AlarmManager.RTC_WAKEUP, triggerTime, mInterval, pendingIntent); 

私はそれを修正する方法がわかりません。助けてください!! ~~この回答から

答えて

1

、また、これはアラームの種類の違いを伝える Android Alarm What is the difference between four types of Alarm that AlarmManager provides and when to use what?

https://developer.android.com/training/scheduling/alarms.html

ELAPSED_REALTIMEを

それはブート以来、トリガされます時間。 300000に設定すると、アラームは5分ごとにトリガーされ、現在の時間を考慮しません。

RTC

それは意味が考慮して、ブート時間がかかることはありませんし、指定された時間にトリガするクロック時間ごとにトリガされます。この、他の

alarmManager.setRepeating(AlarmManager.ELAPSED_REALTIME_WAKEUP, triggerTime, mInterval, pendingIntent); 

あなたは、私は両方とも私のニーズに働いていないしてみてくださいしているデバイス

alarmManager.setRepeating(AlarmManager.ELAPSED_REALTIME, triggerTime, mInterval, pendingIntent); 
+0

を覚ますしたくない場合は、これを使用してデバイスの使用をウェイクアップする

。おかげでバットキャット。 – Joyofio987

+0

アラームマネージャの種類が狂っています。何年もこの問題があるようです。 Androidチームはまだそれを調べていません。 – Joyofio987

+0

アラームマネージャは信頼できません! – Joyofio987