Reputation: 17349
I just published my first application to Google Marketplace and received the information, that the app crashed - I got two stacktraces, one of them for example:
android.view.WindowManager$BadTokenException: Unable to add window -- token android.os.BinderProxy@45681318 is not valid; is your activity running?
at android.view.ViewRoot.setView(ViewRoot.java:468)
at android.view.WindowManagerImpl.addView(WindowManagerImpl.java:177)
at android.view.WindowManagerImpl.addView(WindowManagerImpl.java:91)
at android.view.Window$LocalWindowManager.addView(Window.java:424)
at android.app.Dialog.show(Dialog.java:239)
at abc.de.f.MyTask.onPreExecute(MyTask.java:52)
There's only one possibility to get to method onPreExecute() in MyTask - and it's not crashing in the emulator or on my physical device. But it seems to crash sometimes "out in the wild".
What would your first steps be to get to the reason?
Thanks A LOT,
Stefan
EDIT:
@Override
protected void onPreExecute() {
this.dialog.setMessage(((Activity) listener).getString(R.string.daten_werden_geladen));
this.dialog.show();
}
this.dialog.setMessage works, but show() doesn't... :(
Upvotes: 4
Views: 485
Reputation: 856
we can not use getApplicationContext()
to get the context,we must use activity to get Context.because only activity can add view
Upvotes: 0
Reputation: 6186
swalkner , it seems you need to take care of configuration changes in your app .Check this
Upvotes: 0
Reputation: 33983
Looks like you are updating the UI or showing a dialog from the onPreExecute() using the context of an activity which is closed. I guess there is a logical mistake in your task implementation. U should check if the activity is running before u update the UI using the context or if u are holding a reference to a View from the activity.
EDIT: Instead of using the Activity's context for getting the string resource use try using your application's context.
this.dialog.setMessage(((Activity) listener).getApplicationContext().getString(R.string.daten_werden_geladen));
Upvotes: 5
Reputation: 101
It looks to me that your activity is not yet running (or already disappeared as mentioned before)
It may depend on how the threads execute and also the life cycle of the application is not exactly the same on all the Android versions, I'd try to replicate it in emulators with 1.6, 2.1 & 2.2 at least. Also the market report may tell you if it only happens in a particular device.
I'll not be surprised if some manufacturer change has impacted in the way the Activity life cycle is performed. I'd try to check on at least on HTC Sense device and maybe on some LG, Samsung or Motorola since all have some UI tweaks on top of android.
One possible solution (but it is just a hack and not solving the problem) is to delay the execution of that code using postDelayed, by doing it you are sure it goes into the UI thread after some ms. As I said it will not attack the source of the problem, but it may make it disappear.
Upvotes: 0