Q:

alarm manager stop when change system clock

I have a service that runs in background. I am using alarm manager to start this service. It works fine but when i change the system clock in my device or in the simulator the alarm manager stops.
public void startAzanService() {
Calendar cal = Calendar.getInstance();
Intent intent = new Intent(this, CheckAzan.class);
PendingIntent pintent = PendingIntent.getService(this, 0, intent, 0);
AlarmManager alarm = (AlarmManager)getSystemService(Context.ALARM_SERVICE);
    //repeat the action every 5 secionde
alarm.setRepeating(AlarmManager.RTC_WAKEUP, cal.getTimeInMillis(), 5000, pintent); 
}

A:

You can overcome this problem by Listening to the time changing Broadcast. Do the following:-
1)Create BroadcastReceiver in you Manifest file:- 
<receiver android:name=".TimeChangeReceiver">
        <intent-filter >
            <action android:name="android.intent.action.TIME_SET"/>
        </intent-filter>
</receiver>

2)Create the receiver class:-
public class TimeChangeReceiver extends BroadcastReceiver{

@Override
public void onReceive(final Context arg0, Intent arg1) {
    //Call your Alarm setting code
    Calendar cal = Calendar.getInstance();
    Intent intent = new Intent(this, CheckAzan.class);
    PendingIntent pintent = PendingIntent.getService(this, 0, intent, 0);
    AlarmManager alarm = (AlarmManager)getSystemService(Context.ALARM_SERVICE);
    //repeat the action every 5 secionde
    alarm.setRepeating(AlarmManager.RTC_WAKEUP, cal.getTimeInMillis(), 5000, pintent);
   }
}

*Assuming that your don`t have any problem with your code :)
This link is also a good Tutorial of the BroadcastReceiver

