0

I have built two different flavors of the same app, while running on the same device If I logout from one app it logs out the other app as well. In my app Logout is a network call so when I click one logout button I can see network calls for both the apps. I am using Retrofit to make network calls. Once logout is clicked I am pushing Logout event on eventbus and MainLandingActivity is subscribed to that.

@Override
public void onClick(DialogInterface dialogInterface, int i) {
                                 showSimpleProgressDialog(context);
    EventBus eventBus = EventBus.getDefault();
    LogoutEvent logoutEvent = new LogoutEvent(false, context);
    eventBus.post(logoutEvent);
}

Here is the Subscription code

@Subscribe
public void onLogout(LogoutEvent logoutEvent) {
    try {
        if (NetworkReceiver.isConnected) {
                Intent intent = new Intent(this, UploadDataService.class);
                intent.putExtra(Const.SERVICE_KEY, Const.MAIN_LANDING_LOGOUT);
                startService(intent);
            } else {
                RUtils.removeSimpleProgressDialog();
                RUtils.showSnackbar(rvMainLanding, getString(R.string.logout_no_internet_error), Snackbar.LENGTH_LONG);
            }

    } catch (Exception e) {
        e.printStackTrace();
        Crashlytics.logException(e);
        RUtils.removeSimpleProgressDialog();
        RUtils.showSnackbar(rvMainLanding, getString(R.string.logout_failed_error), Snackbar.LENGTH_LONG);
    }
}
pradex
  • 328
  • 4
  • 18

1 Answers1

0

Got it working, UploadDataService was sending global Broadcast for logout. Replaced it with LocalBroadcastManager and it solved the issue.

pradex
  • 328
  • 4
  • 18