How To Popup Alarm Message Without Any Activity In Background?
In my android i app i can alarm functionality and as well logout functionality. After setting my alarm time i am exiting the app by clicking the logout button. I am using
Solution 1:
You should use Alarm Manager to set alarms in Android. The alarm manager holds your alarm and fire an pending intent on alarm time.
First create a pending intent like this :
pendingIntent = PendingIntent.getService(CONTEXT, ALARM_ID, INTENT_TO_LAUNCH, 0);
Then use this pending intent to set an Alarm like this :
AlarmManager alarmManager = (AlarmManager)getSystemService(ALARM_SERVICE);
alarmManager.set(AlarmManager.RTC_WAKEUP, ALARM_TIME, pendingIntent);
This will start the pending intent at given time.
To remove an alarm you have to recreate the same Pending Intent with same ALARM_ID :
alarmManager.cancel(pendingIntent);
Solution 2:
First create a pending intent like this :
pendingIntent = PendingIntent.getService(context, alarm_id, Pass your data with intent, PendingIntent.FLAG_UPDATE_CURRENT);
Set an Alarm like this :
AlarmManager am = (AlarmManager)getSystemService(ALARM_SERVICE);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
//19 4.4and above api level
am.setExact(AlarmManager.RTC_WAKEUP, cal.getTimeInMillis() + AlarmManager.INTERVAL_DAY, sender);
} else {
//below 19 4.4
am.set(AlarmManager.RTC_WAKEUP, cal.getTimeInMillis() + AlarmManager.INTERVAL_DAY, sender);
}
This will start the pending intent at given time.
To remove an alarm you have to Use the same Pending Intent with same ALARM_ID
:
am.cancel(pendingIntent);
Now You need to create One Service to catch your Alarm.
Post a Comment for "How To Popup Alarm Message Without Any Activity In Background?"