Tapadoo / Alerter

An Android Alerting Library
MIT License
5.52k stars 632 forks source link

Crash when another Activity is launched while the Alert is being displayed #259

Closed jassielcastro closed 3 years ago

jassielcastro commented 3 years ago

As mentioned in the title, any app that tries to launch a new activity or change fragment while the Alert is being displayed, the app will crash... A solution we found was to put a postDelay while Alerter.isShowing()

long delay = 0L;
if (Alerter.isShowing()) {
    Alerter.hide();
    delay = 350L;
}

view.postDelayed(() -> {
   launchActivity();
}, delay);

but there is no way to add a callBack in the Alerter.hide() method when the hide is finished? This to know when the Alerter is already removed.

kpmmmurphy commented 3 years ago

Hey @jassielcastro, thanks for flagging this. Could you try calling '.hide()' in your calling Activity's 'onPause' or 'onStop' lifecycle method?

jassielcastro commented 3 years ago

@kpmmmurphy the crash still, because at the moment of calling 'onPause' or 'onStop' the animation of removing the view has not yet finished:

// This is the part of your code that still doesn't finish removing the view.
public static void clearCurrent(...) {
...
    ViewCompat.animate(childView).alpha(0).withEndAction(getRemoveViewRunnable(childView));
...
}

And when the new Activity is launched, the Alert is still visible.

kpmmmurphy commented 3 years ago

Hey @jassielcastro, more then happy to review a PR with a fix for this if you can implement one!

jassielcastro commented 3 years ago

Sure @kpmmmurphy let me take some time!

jassielcastro commented 3 years ago

@kpmmmurphy you already have a listener:

fun setOnHideListener(listener: OnHideAlertListener): Alerter {

My bad... Im using a very old version of your library.