-3

I have a alarm manager that call a particular service after every 1 minute which do some calculations and send a broadcast to broadcast receiver. I have done this using alarm manager setRepeating().

Here it my code:

Alarm manager:

    Intent serviceIntent = new Intent(this, PrayerNotifyService.class);
    PendingIntent pintent = PendingIntent.getService(this, 0, serviceIntent, 0);

    AlarmManager alarm = (AlarmManager) getSystemService(Context.ALARM_SERVICE);

    alarm.setRepeating(AlarmManager.RTC_WAKEUP, System.currentTimeMillis(), 60000, pintent);

It works fine but after rebooting a mobile phone, alarm manager not calling the service.

I have searched on internet and found some solutions like below but they didn't worked for me.

i have also give Boot Complete permission

    <uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED"/>

My Receiver in Manifest:

    <receiver
        android:name=".NotificationReceiver"
        android:enabled="true"
        android:exported="true" >

           <action android:name="android.intent.action.BOOT_COMPLETED" />

    </receiver>

Can any one tell me how to solve this issue?

Asad Haider
  • 504
  • 1
  • 5
  • 17
  • 1
    Customized Alarms gets destroyed when device gets shutsdown, You need to re-register the Alarm whenever device is boot. Check this question http://stackoverflow.com/q/12034357/5505915 – Arjun Nov 03 '15 at 12:20
  • Ca you tell me the right way of doing work in background after every minute? I didn't want to use sticky service that runs all the time – Asad Haider Nov 03 '15 at 12:50
  • 1
    @asadhaider IMHO you should not be using Alarms at such a low frequency. It's better to use a Timer in such a scenario. What is the purpose of setting an Alarm every minute? – iZBasit Nov 03 '15 at 12:55
  • I am workin on application which notify a user on prayer time. Prayer time is calculated everyday because it is changing day by day so i have to calculaye it daily. I.want to notify a user on prayer time how to do this? – Asad Haider Nov 03 '15 at 13:01

1 Answers1

0

Your broadCast should start service, not alarmManager.

1)Boot device 2)start service from bootReceiver 3)in service start alarmManager.

Hope it helps.

Android Android
  • 724
  • 1
  • 7
  • 20
  • Is this is write approach that i can trigger broadcast after every minute and do my work in onreceive method instead of service? – Asad Haider Nov 03 '15 at 12:48