Error:Binderproxy@45D459C0 Is Not Valid; Is Your Activity Running

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.

Unable to add window -- token android.os.BinderProxy is not valid; is your activity running?

This can occur when you are showing the dialog for a context that no longer exists. A common case - if the 'show dialog' operation is after an asynchronous operation, and during that operation the original activity (that is to be the parent of your dialog) is destroyed. For a good description, see this blog post and comments:

http://dimitar.me/android-displaying-dialogs-from-background-threads/

From the stack trace above, it appears that the facebook library spins off the auth operation asynchronously, and you have a Handler - Callback mechanism (onComplete called on a listener) that could easily create this scenario.

When I've seen this reported in my app, its pretty rare and matches the experience in the blog post. Something went wrong for the activity/it was destroyed during the work of the the AsyncTask. I don't know how your modification could result in this every time, but perhaps you are referencing an Activity as the context for the dialog that is always destroyed by the time your code executes?

Also, while I'm not sure if this is the best way to tell if your activity is running, see this answer for one method of doing so:

Check whether activity is active

Logout dialog error: token android.os.BinderProxy@4276c0e8 is not valid; is your activity running

This can occur when you are showing the dialog for a context that no longer exists. A common case - if the 'show dialog' operation is after an asynchronous operation, and during that operation the original activity (that is to be the parent of your dialog) is destroyed.

This might be similar here.
I hope it helps.

handleWindowVisibility: no activity for token android.os.BinderProxy

This code Seems correct but my only suspicion is that when you want to open the new activity in startActivity(intent), the error occurs.

So check the next fired class named SelfieCapture.class to see whether it extends from MyBaseActivity also.

Also consider that when you want to get the currentActivity, if you put it in onCreate, you will get null. For more information please refer to Understand the Activity Lifecycle.



Related Topics



Leave a reply



Submit