In my manifest file, I declared the recipient. (in the following way)
<receiver android:name=".OnAlarmReceive" />
however, as soon as I turn off my application, I cannot receive warnings and notifications. Apparently, the OnReceive call in my Broadcast receiver never made.
public class OnAlarmReceive extends BroadcastReceiver { @Override public void onReceive(Context context, Intent arg1) {
Inside MainActivity, my alarm manager class is as follows.
AlarmManager alarmManager = (AlarmManager) getSystemService(ALARM_SERVICE); Intent intent = new Intent("MY_ALARM_NOTIFICATION"); intent.setClass(this, OnAlarmReceive.class); intent.putExtra("message", message); PendingIntent pendingIntent = PendingIntent .getBroadcast(MainActivity.this, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT); Calendar timeCal = Calendar.getInstance(); timeCal.set(Calendar.HOUR_OF_DAY, hour); timeCal.set(Calendar.MINUTE, minutes); alarmManager.set(AlarmManager.RTC_WAKEUP, timeCal.getTimeInMillis(), pendingIntent);
and my manifest as follows:
<receiver android:name=".OnAlarmReceive"> <intent-filter android:priority="1"> <action android:name="MY_ALARM_NOTIFICATION"/> </intent-filter> </receiver>
What should I do to receive notifications / alarms even if I turn off my application. Background service?
source share