EventBus icon indicating copy to clipboard operation
EventBus copied to clipboard

ErrorDialogManager miss @Subscribe

Open LittleNum opened this issue 5 years ago • 1 comments

Inner class of ErrorDialogManager such as SupportManagerFragment and HoneycombManagerFragment miss @Subscribe on the method onEventMainThread.It makes crash.

public static class SupportManagerFragment extends Fragment { protected boolean finishAfterDialog; protected Bundle argumentsForErrorDialog; private EventBus eventBus; private boolean skipRegisterOnNextResume; private Object executionScope;

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        eventBus = ErrorDialogManager.factory.config.getEventBus();
        eventBus.register(this);
        skipRegisterOnNextResume = true;
    }

    @Override
    public void onResume() {
        super.onResume();
        if (skipRegisterOnNextResume) {
            // registered in onCreate, skip registration in this run
            skipRegisterOnNextResume = false;
        } else {
            eventBus = ErrorDialogManager.factory.config.getEventBus();
            eventBus.register(this);
        }
    }

    @Override
    public void onPause() {
        eventBus.unregister(this);
        super.onPause();
    }

    public void onEventMainThread(ThrowableFailureEvent event) {
        if (!isInExecutionScope(executionScope, event)) {
            return;
        }
        checkLogException(event);
        // Execute pending commits before finding to avoid multiple error fragments being shown
        FragmentManager fm = getFragmentManager();
        fm.executePendingTransactions();

        DialogFragment existingFragment = (DialogFragment) fm.findFragmentByTag(TAG_ERROR_DIALOG);
        if (existingFragment != null) {
            // Just show the latest error
            existingFragment.dismiss();
        }

        android.support.v4.app.DialogFragment errorFragment = (android.support.v4.app.DialogFragment) factory
                .prepareErrorFragment(event, finishAfterDialog, argumentsForErrorDialog);
        if (errorFragment != null) {
            errorFragment.show(fm, TAG_ERROR_DIALOG);
        }
    }

    public static void attachTo(Activity activity, Object executionScope, boolean finishAfterDialog,
            Bundle argumentsForErrorDialog) {
        FragmentManager fm = ((FragmentActivity) activity).getSupportFragmentManager();
        SupportManagerFragment fragment = (SupportManagerFragment) fm.findFragmentByTag(TAG_ERROR_DIALOG_MANAGER);
        if (fragment == null) {
            fragment = new SupportManagerFragment();
            fm.beginTransaction().add(fragment, TAG_ERROR_DIALOG_MANAGER).commit();
            fm.executePendingTransactions();
        }
        fragment.finishAfterDialog = finishAfterDialog;
        fragment.argumentsForErrorDialog = argumentsForErrorDialog;
        fragment.executionScope = executionScope;
    }
}

LittleNum avatar Jul 30 '19 03:07 LittleNum

Please do not use ErrorDialogManager or related classes, this code is no longer maintained. We should probably remove it. Preferably write your own error handling.

greenrobot-team avatar Aug 06 '19 11:08 greenrobot-team