2

I have implemented a service to run with the alarm manager. I read this link: Should I use android: process =“:remote” in my receiver?

I thought this would be a nice feature for my app, since i want the service to keep running after my app is down.
But when i add this line of configuration to my receiver on the manifest, my service stops being called.

Any clues?

Here is my receiver declaration:

This works:

<receiver
        android:name=".service.MyAlarmReceiver"
        android:enabled="true"
        android:exported="false">
        <intent-filter>
            <action android:name=".service.MyAlarmReceiver"></action>
        </intent-filter>
    </receiver>

This wont'n work:

<receiver
        android:name=".service.MyAlarmReceiver"
        android:enabled="true"
        android:process=":remote"
        android:exported="false">
        <intent-filter>
            <action android:name=".service.MyAlarmReceiver"></action>
        </intent-filter>
    </receiver>


public class MyAlarmReceiver extends BroadcastReceiver {
    public static final int REQUEST_CODE = 12345;

    @Override
    public void onReceive(Context context, Intent intent) {
        Log.d(TAG, "Time to start scan service!");
        Intent intent = new Intent(context, BeaconFinderService.class);
        context.startService(intent);
    }
}

This is how i start my alarm manager:

// Construct an intent that will execute the AlarmReceiver
Intent intent = new Intent(getApplicationContext(), MyAlarmReceiver.class);
final PendingIntent pIntent = PendingIntent.getBroadcast(getApplicationContext(), MyAlarmReceiver.REQUEST_CODE, intent, PendingIntent.FLAG_UPDATE_CURRENT);

AlarmManager alarmManager = (AlarmManager) getSystemService(Context.ALARM_SERVICE);
alarmManager.setInexactRepeating(AlarmManager.RTC_WAKEUP, System.currentTimeMillis(), Constants.BLE_SERVICE_LOOP_TIME, pIntent);
Community
  • 1
  • 1
Nacho
  • 2,057
  • 2
  • 23
  • 32
  • What service are you referring to? What process is *it* in? – CommonsWare Mar 18 '17 at 22:38
  • @CommonsWare i added my code for my broadcast receiver. The issue is not the service (i think), the logging on the onReceive method won't be called as i add remote to the manifest – Nacho Mar 18 '17 at 22:54
  • How are you creating the `Intent` for `AlarmManager`? You should be using an explicit `Intent` (and, as a side effect, getting rid of the unnecessary ``). [NOTE: apologies for having screwed up my earlier comment -- this is the fixed one]. – CommonsWare Mar 18 '17 at 23:19
  • @CommonsWare i added the code for how i create the Intent. I also removed the intent-filter, i thought it helped compatibility... – Nacho Mar 20 '17 at 13:02
  • OK, this all seems fine. When the alarm goes off, are any relevant messages from the system (not your app) showing up in LogCat? – CommonsWare Mar 20 '17 at 13:03
  • @CommonsWare i found it!! i was debugging my app process, but i had to analyze my.app.package:remote!!! Thanks! Plz add it as a response and i mark it as resolved, it could help some other distracted as me! – Nacho Mar 20 '17 at 13:26
  • 1
    I recommend that you answer your own question, as you are in better position to explain what you were doing wrong and what it took to correct matters. – CommonsWare Mar 20 '17 at 13:27
  • I was having the exact same issue and was trying to figure it out for days! Difference was that I was not using an intent filter. My alarm was getting triggered as per "adb shell dumpsys alarm" but the broadcastreceiver onreceive was not getting triggered. I kept looking up online but didn't find a thing. Finally found this, and on removing the process: ":remote" bit it started working! Thanks a bunch! – s1d Sep 28 '17 at 14:56

1 Answers1

0

When you configure your service to run in remote mode (android:process=":remote"), you will have to debug the process :remote instead as usual .

Personal bug: So I was having an exception when trying to access FirebaseUser on the service. When in remote mode, you can't access the FirebaseUser, since your process runs on another context. I had to pass the user through intent extras when initializing the service. That was all!

Nacho
  • 2,057
  • 2
  • 23
  • 32