Error : BinderProxy@45d459c0 is not valid; is your activity running?

This is most likely happening because you are trying to show a dialog after execution of a background thread, while the Activity is being destroyed.

I was seeing this error reported once in a while from some of my apps when the activity calling the dialog was finishing for some reason or another when it tried to show a dialog. Here's what solved it for me:

if(!((Activity) context).isFinishing())
{
    //show dialog
}

I've been using this to work around the issue on older versions of Android for several years now, and haven't seen the crash since.

2021 Update

It's been noted in some of the comments that it's bad to blindly cast Context to an Activity. I agree!

When I'm writing similar code these days in a Fragment (8+ years after the original answer was provided), I do it more like this:

if (!requireActivity().isFinishing) {
     // show dialog
}

The main takeaway is that trying to show a dialog or update any UI after the hosting Activity has been killed will result in a crash. Do what you can to prevent that by killing your background threads when your Activity is killed, or at a minimum, use the answer here to stop your app from crashing.


I faced the same problem and used the code proposed by DiscDev above with minor changes as follows:

if (!MainActivity.this.isFinishing()){
    alertDialog.show();
}

if dialog is trowing this problem because of the thread you should do run this on UI thread like that :-

runOnUiThread(new Runnable() {
            @Override
            public void run() {
                dialog.show();

            }
        });

This error occurs when you are showing the dialog for a context that no longer exists.

Before calling .show() check that activity/context is not finishing

if (!(context instanceof Activity && ((Activity) context).isFinishing())) {
    alert.show();
}