androidlocalbroadcastmanager

LocalBroadcastManager: Receive events when app is closed


I try to integrate the beaconinside sdk into my app and I want to receive the events sent through the Beaconservice even when my app is closed and removed from the app drawer (recent apps).

Now my code looks like so

BeaconFragment

@Override
public void onCreate() {
    super.onCreate();

    // init beaconinside sdk using my token
    BeaconService.init(this, API_TOKEN);
}

BeaconHandler

public class BeaconHandler extends BroadcastReceiver {
    // ...

    public void onReceive(Context context, Intent intent) {
        // ...
    }
}

BackgroundBeaconService

public class BackgroundBeaconservice extends IntentService {
    // ...
    public void onCreate() {
        // setup intent filter for beacon events
        IntentFilter beaconListenerFilter = new IntentFilter();
            // add intent filter for BeaconService (e.g. REGION_ENTER)

        // beacon event handler
        beaconListener = new BeaconHandler(this);

        // register the event handler to the LocalBroadcastManager
        registerBeaconEventHandler(beaconListener, beaconListenerFilter);
    }

    private void registerBeaconEventHandler(BroadcastReceiver receiver, IntentFilter filter) {
        LocalBroadcastManager.getInstance(this).registerReceiver(receiver, filter);
    }
}

So far it works but when I close the app from the recent app drawer, it stops working. I wrote to the Tech Support of Beaconinside and they told me to use a Service to receive events from the LocalBroadcastManager in the background.

Which aspects of my code do I need to move in the service class and which can stay where they are?


Solution

  • As it turns out, this problem can't be solved without the interaction of beaconinside. So I sent a mail to them and they told me that this problem is fixed in the new version (2.8.0), which will be released this week.