I am using a countdown timer class and in the onfinish() state of that class I am creating a notification. Here is the Onfinish method’s code:
public void onFinish() {
notificate();
Log.i("Aler Resume", "Finished");
remtime.setText("0 : 00 : 00");
textCondition.setText(getString(R.string.BuddyAlertExpired));
}
In the notificate() method I wrote:
private void notificate() {
NotificationManager notifManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
Notification note = new Notification(R.drawable.ic_launcher, "New E-mail", System.currentTimeMillis());
PendingIntent intent = PendingIntent.getActivity(this, 0, new Intent(this, AlertResume.class), 0);
note.setLatestEventInfo(this, "Buddy Alert", getString(R.string.BuddyAlertExpired), intent);
note.defaults= Notification.DEFAULT_VIBRATE;
note.defaults=Notification.DEFAULT_SOUND;
notifManager.notify(NOTIF_ID, note);
}
Its working fine when I keep my application open. But when I go back from the application the onfinish method is being called and I can see the log correctly but the notofication method is not working and doesnt show any notification. Is there any mistake?
When you go away from the app, It can happen that Android think your process running of the CountDown Timer as an Spam or Extra and not-intended. and Finish it of..(Like it think you forgot to close let me close)
So better Use AlarmManager for the above stuff like to set PendingIntent – Notification,AT THE TIME WHERE YOU START YOUR COUNT-DOWN TIMER ALSO SET NOTIFICATION WITH PENDING INTENT USING ALARM MANAGER.