0

I'm building app that reminds user of unread messages. My problem is that after user swipes it out from a list with last used apps, both my broadcast receiver and alarm manager don't work. Is there any solution for that issue?

I have read that adding ' android:process=":remote" 'in receiver's manifest may help, but it doesn't. The app is 'unfortunately closed' after receiving message when this line is in the manifest.

I wonder how do apps like Messenger or Mail work? They have to notify user when the message is received and they are being swiped out by users, same as the other apps.

Here is how I set my alarm:

Intent i = new Intent(MainActivity.mContext,AlarmReceiver.class);
i.putExtra("number",numerNadawcy);
i.putExtra("hour",h);
i.putExtra("minute",m);
i.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
PendingIntent alarmIntent = PendingIntent.getBroadcast(MainActivity.mContext, 123, i, 0);

AlarmManager alarmMgr = (AlarmManager)context.getSystemService(Context.ALARM_SERVICE);
if(Build.VERSION.SDK_INT>=19)
{
         alarmMgr.setExact(AlarmManager.RTC_WAKEUP,System.currentTimeMillis()+h*60*60*1000+m*60*1000,alarmIntent);


}
else
{
         alarmMgr.setRepeating(AlarmManager.RTC_WAKEUP, System.currentTimeMillis(),h*60*60*1000+m*60*1000, alarmIntent);
}
Suchy1270
  • 19
  • 5
  • 1
    how you set alarm manager ? Please post some relevant code triggering alarm, broadcast etc.. – Aalap Patel Aug 31 '17 at 14:32
  • you put any code that you want desire to work in background inside a service(s). please refer to this https://stackoverflow.com/a/19317044/7689086 – Achmad Naufal Syafiq Aug 31 '17 at 15:00
  • Have you seen this : https://stackoverflow.com/questions/32811857/alarmmanager-stops-after-removing-app-from-recents-apps – marcinj Aug 31 '17 at 15:28
  • @marcinj your link seems to refer to the solution I have mentioned in my post: adding 'android:process=":remote"', but it does not work for me. – Suchy1270 Sep 01 '17 at 13:40
  • @AchmadNaufalSyafiq, I don't understand. Do you mean to set alarm inside the service? I have added one service that is started inside my alarm receiver (it checks if the message has been read), but it still doesn't work – Suchy1270 Sep 01 '17 at 13:45
  • @Suchy1270 if you have read that SO then you should know there is no easy way to fix it. From what I know you could try using GCM to send messages to your app to wake it. Messanger or Mail might have some system priviledges. – marcinj Sep 01 '17 at 14:01

0 Answers0