user2638180
user2638180

Reputation: 1023

Cannot execute LocalBroadcastManager from JobIntentService

I've a JobIntentService, in which if certain conditions are met, it must launch a LocalBroadCastManager that is received by my MainActivity.

I'm doing it this way:

 LocalBroadcastManager localBroadcastManager = LocalBroadcastManager
                .getInstance(MyJobIntentService.this);


      [...]


                    localBroadcastManager.sendBroadcast(new Intent(
                            "com.durga.action.exit2"));

Having defined the LocalBroadCastManager this way in my main activity:

    LocalBroadcastManager mLocalBroadcastManager3;
    BroadcastReceiver mBroadcastReceiver3 = new BroadcastReceiver() {


        @Override
        public void onReceive(Context context, Intent intent) {
            if (intent.getAction().equals("com.durga.action.exit2")) {
                [my code]
            }
        }
    };

    mLocalBroadcastManager3 = LocalBroadcastManager.getInstance(this);
    IntentFilter mIntentFilter3 = new IntentFilter();
    mIntentFilter3.addAction("com.durga.action.exit2");
    mLocalBroadcastManager3.registerReceiver(mBroadcastReceiver3, mIntentFilter3);

Up until now I was using a similar code that used services instead of JobIntentServices, but from API 26 it's no longer possible to execute services in some situations I'd need, so instead I need to use JobIntentServices.

The code was this one:

LocalBroadcastManager localBroadcastManager = LocalBroadcastManager
                    .getInstance(MyService.this);


          [...]


                        localBroadcastManager.sendBroadcast(new Intent(
                                "com.durga.action.exit2"));

What could I do so the JobIntentService launches the LocalBroadcastManager successfully?

I'm not able to give further detail on which the error is, as when executed on emulator it just finishes the app with "the app has stopped working message despite the code being in a try, catch block. It's also basically impossible due to my computer resources to debug API 26 in emulator to get more information and also I don't have a physical device with API 26.

Upvotes: 1

Views: 97

Answers (0)

Related Questions