Android: two error only sometimes/on some devices
android, crash
Solution
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));
Problem
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... :(