Android: two errors only sometimes / on some devices

I just published my first application on the Google Marketplace and got information that the application crashed - I have two stacks, one of which, 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 is only one way to get the onPreExecute () method in MyTask - and this is not a failure in the emulator or on my physical device. But it seems that he sometimes "breaks" in the wild.

What would be your first steps to get to the cause?

Thanks LOT

Stephen

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 () is not ...: (

+4
source share
4 answers

It looks like you are updating the user interface or showing a dialog from onPreExecute () using a closed-action context. I assume that there is a logical error in the implementation of your task. U should check if the action is executed before you update the user interface using the context, or if u holds a link to the view from the action.

EDIT: Instead of using an Activity context to get the use of a string resource, use your application context.

 this.dialog.setMessage(((Activity) listener).getApplicationContext().getString(R.string.daten_werden_geladen)); 
+5
source

It seems to me that your activity has not yet started (or has already disappeared, as mentioned earlier)

This may depend on how the threads are executed, as well as on the application life cycle not in all versions of Android, I would try to replicate it in emulators with 1.6, 2.1 and 2.2 at least. Also, a market report can tell you if this only happens on a specific device.

I would not be surprised if some change in the manufacturer influenced the way the activity life cycle is carried out. I would try to check at least on the HTC Sense device and, possibly, on some LG, Samsung or Motorola, since everyone has some user interface settings on top of Android.

One of the possible solutions (but this is just a hack and not a solution to the problem) is to delay the execution of this code using postDelayed, by doing this, you are sure that it goes into the user interface stream after some ms. As I said, it will not attack the source of the problem, but it can make it disappear.

0
source

swalkner, it looks like you need to take care of the configuration changes in your application. Check this

0
source

we cannot use getApplicationContext() to get context, we must use activity to get Context.because only activity can add a view

0
source

All Articles