I have one class called StopAlarmReceiver and another BootHandler.
The BootHandler resets the alarm after reboot, which was set before the boot. My problem is that the BootHandler sets the alarm but not getting fired.
Entries in Manifest file.
Code in BootHandler.
The above code runs without any problem immediately after reboot and I can see the log with the time. But the problem is that it should fire after each and every five seconds but it won't!
I hold the below permission .
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED"/>
Please help!
The BootHandler resets the alarm after reboot, which was set before the boot. My problem is that the BootHandler sets the alarm but not getting fired.
Entries in Manifest file.
Code:
<receiver
android:name="com.sign.android.myscheduler.app.StopAlarmReceiver"
android:enabled="true"
android:exported="true" >
</receiver>
<receiver
android:name="com.sign.android.myscheduler.app.BootHandler"
android:enabled="true"
android:exported="true" >
<intent-filter>
<action android:name="android.intent.action.BOOT_COMPLETED"/>
</intent-filter>
</receiver>
Code in BootHandler.
Code:
AlarmManager mgr= (AlarmManager)context.getSystemService(Context.ALARM_SERVICE);
Intent i = new Intent(context, StopAlarmReceiver.class);
PendingIntent pi = PendingIntent.getService(context, 1, i, 0);
long time = sharedPreferences.getLong("Old_time", 0);
Log.e(TAG, "New time: " +new Date(SystemClock.elapsedRealtime() + time));
mgr.setRepeating(AlarmManager.ELAPSED_REALTIME, SystemClock.elapsedRealtime() + time, 5000, pi);
The above code runs without any problem immediately after reboot and I can see the log with the time. But the problem is that it should fire after each and every five seconds but it won't!
I hold the below permission .
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED"/>
Please help!