Hello everybody,
I encounter a problem with a ProgressDialog in a PreferencesActivity
in my application.
What I want to do is pop up a ProgressDialog after the user has
changed his username or password during the check on the remote
server.
In the onSharedPreferenceChanged() I call the ProgressDialog.show()
method. Sometimes it works fine, sometimes not at all: I get an
exception:
Uncaught handler: thread main exiting due to uncaught exception
E/AndroidRuntime(17124): android.view.WindowManager$BadTokenException:
Unable to add window -- token android.os.binderpr...@44f75b40 is not
valid; is your activity running?
E/AndroidRuntime(17124): at
android.view.ViewRoot.setView(ViewRoot.java:468)
E/AndroidRuntime(17124): at
android.view.WindowManagerImpl.addView(WindowManagerImpl.java:177)
E/AndroidRuntime(17124): at
android.view.WindowManagerImpl.addView(WindowManagerImpl.java:91)
E/AndroidRuntime(17124): at android.view.Window
$LocalWindowManager.addView(Window.java:424)
E/AndroidRuntime(17124): at android.app.Dialog.show(Dialog.java:239)
E/AndroidRuntime(17124): at
fr.application.activity.ProgressDialogHelper.showProgressDialog(ProgressDialogHelper.java:
26)
E/AndroidRuntime(17124): at
fr.application.controller.ControllerPreference.onSharedPreferenceChanged(ControllerPreference.java:
58)
E/AndroidRuntime(17124): at android.app.ApplicationContext
$SharedPreferencesImpl$EditorImpl.commit(ApplicationContext.java:2719)
E/AndroidRuntime(17124): at
android.preference.Preference.tryCommit(Preference.java:1199)
E/AndroidRuntime(17124): at
android.preference.Preference.persistString(Preference.java:1226)
E/AndroidRuntime(17124): at
android.preference.EditTextPreference.setText(EditTextPreference.java:
89)
E/AndroidRuntime(17124): at
android.preference.EditTextPreference.onDialogClosed(EditTextPreference.java:
143)
E/AndroidRuntime(17124): at
android.preference.DialogPreference.onDismiss(DialogPreference.java:
384)
E/AndroidRuntime(17124): at android.app.Dialog
$ListenersHandler.handleMessage(Dialog.java:1058)
E/AndroidRuntime(17124): at
android.os.Handler.dispatchMessage(Handler.java:99)
E/AndroidRuntime(17124): at android.os.Looper.loop(Looper.java:123)
E/AndroidRuntime(17124): at
android.app.ActivityThread.main(ActivityThread.java:4363)
E/AndroidRuntime(17124): at
java.lang.reflect.Method.invokeNative(Native Method)
E/AndroidRuntime(17124): at
java.lang.reflect.Method.invoke(Method.java:521)
E/AndroidRuntime(17124): at com.android.internal.os.ZygoteInit
$MethodAndArgsCaller.run(ZygoteInit.java:860)
E/AndroidRuntime(17124): at
com.android.internal.os.ZygoteInit.main(ZygoteInit.java:618)
E/AndroidRuntime(17124): at dalvik.system.NativeStart.main(Native
Method)
The source code:
public class ActivityPreference extends PreferenceActivity implements
OnSharedPreferenceChangeListener
{
private final static String TAG =
ActivityPreference.class.getSimpleName();
private final static boolean DEBUG = true;
private ModelUserInterface mModel;
private ProgressDialog mProgressDialog;
private String mUserName;
private String mPassword;
@Override
protected void onCreate(Bundle savedInstanceState)
{
if (DEBUG)Log.d(TAG, "onCreate");
super.onCreate(savedInstanceState);
addPreferencesFromResource(R.xml.gazpillagepreference);
mModel = new ModelUser();
mProgressDialog = new ProgressDialog(this);
mProgressDialog.setCancelable(false);
PreferenceManager.getDefaultSharedPreferences(this).registerOnSharedPreferenceChangeListener(this);
}
@Override
public void onSharedPreferenceChanged(SharedPreferences
sharedPreferences, String key)
{
if (DEBUG)Log.d(TAG, "onSharedPreferenceChanged");
// The preferences has changed, reload the user data.
getPreferenceData(sharedPreferences);
// Display the progress dialog with the correct message
mProgressDialog.setMessage(getString(R.string.checking));
mProgressDialog.show();
// Ask to the model if the username and password are valid
mModel.askLoginPasswordValid(mUserName, mPassword);
}
}
The thing I don't understand is why sometimes it works and sometimes
not!
--
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en