Toast in PreferenceActivity is shown late?

This is happening because the onPreferenceClick listener is running in the UI thread. This thread is also the same as the one that handles displaying the Toast Toast#show only pushes a message onto the message queue that will then run code to make the Toast display. That queue won't be processed until after your onPreferenceClick handler is completely finished.

This is happening because the onPreferenceClick listener is running in the UI thread. This thread is also the same as the one that handles displaying the Toast. Toast#show only pushes a message onto the message queue that will then run code to make the Toast display.

That queue won't be processed until after your onPreferenceClick handler is completely finished. You can try: myCheckBox. SetOnPreferenceClickListener(new OnPreferenceClickListener() { @Override public boolean onPreferenceClick(Preference preference) { Toast.

MakeText(Prefs. This, "test", Toast. LENGTH_SHORT).show(); Prefs.this.

RunOnUiThread(new Runnable() { @Override public void run() { doSomething(); } }); return false; } }); This will cause the Toast to post to the message queue then your doSomething will also be posted to the queue after the toast. The downside to this is that there could be UI messages that will be handled before doSomething is called. Also, if doSomething is long running it will monopolize your UI thread and could cause a possible ANR force close.

You may want to think about running doSomething in an AsyncTask if it takes more than 150ms or so.

Thanks for explaining this in detail. The method is actually initiating an OAuth handshake and then starts a new activity showing a WebView to perform the OAuth authorization. So, when the user clicks on the CheckBox, it takes some seconds before the WebView activity is started, because first a connection to Twitter is established to receive the request token.

--> The reason I want to show the toast is to inform the user that something is going on in case he wanders why nothing seems to happen for some seconds (before the WebView activity is started / shown). – Manuel Aug 29 '10 at 18:55 Show an asynctask with a progress dialog – Falmarri Aug 29 '10 at 22:36.

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions