How to get local notification in Android while Application stop?
I am developing one Android Application which uses Local Notification by using Alarm Manager and BroadCast Receiver开发者_StackOverflow中文版. I am receiving notification without any error in default. I am not receiving notification, If i Force Stop my application by using settings-> Application-> ManageApplication-> MyApplication-> ForceStop. My code is
To schedule Event
Calendar cal = Calendar.getInstance();
cal.add(Calendar.MINUTE, 2);
Intent intent = new Intent(this, AlarmReceiver.class);
intent.putExtra("alarm_message", "O'Doyle Rules!");
PendingIntent sender = PendingIntent.getBroadcast(this, 192837,
intent, PendingIntent.FLAG_UPDATE_CURRENT);
AlarmManager am = (AlarmManager) getSystemService(ALARM_SERVICE);
am.set(AlarmManager.RTC_WAKEUP, cal.getTimeInMillis(), sender);
My BroadCast Receiver
try
{
Bundle bundle = intent.getExtras();
String message = bundle.getString("alarm_message");
Toast.makeText(context, message, Toast.LENGTH_SHORT).show();
Intent i=new Intent(context,AlertActivity.class);
i.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
context.startActivity(i);
}
catch (Exception e)
{
e.printStackTrace();
}
Please give me some advise to solve my problem. Thanks in Advance
can you explain it a bit more ... i guess without using any background service or app widget kind of thing how you can expect that your application will continue to run even after force close ???
This won't work, you must do the following:
Calendar cal = Calendar.getInstance();
cal.setTimeInMillis(SystemClock.elapsedRealtime());
cal.add(Calendar.MINUTE, 2);
...and so on...
API forcestoppackage will cancel alarms associated with the package So nothing will happen in the future.
forcestopPackage() will send a broadcast with action "package_restart", AlarmManagerService listen this broadcast and remove all alarm set by the app which is force stopped.
精彩评论