Use runOnUiThread() around your code in the catch block, to have that
stuff be done on the main application thread.

On Tue, Jun 14, 2011 at 6:40 AM, Droid <[email protected]> wrote:
> I am spinning a thread to go online and get data. But if phone is in a
> network hole (no signal) it throws an exception.
> In the exception I try to call Toast or finish() the activity but both
> those cause a crash.
>
> Here's the error and my code:
>  error is:
> 06-14 11:32:01.691: ERROR/AndroidRuntime(7389):
> java.lang.RuntimeException: Can't create handler inside thread that
> has not called Looper.prepare()
>
> here is the code, note the catch clause at the end which is where my
> problem lies:
>
> *********************************************************************************************
>    private Thread checkUpdate = new Thread() {
>        public void run() {
>            try {
>                URL updateURL = new URL("http://search.twitter.com/
> search.json?q="+string_from_speaker);
>                URLConnection conn = updateURL.openConnection();
>                ...
>            } catch (Exception e) {
> // none of these exception handlers work becaue they are in wrong
> thread!! WTF?
> // NOPE tv1.setText(" having trouble getting online"); // TODO
> // NOPE Toast.makeText(IconicAgain.this, "having trouble getting
> online "+ e, Toast.LENGTH_LONG).show();
>            }
>        }
>    };
> ********************************************************************************************
>
> Can I at least stop this thread somehow? Or close the activity
> somehow?
>
> --
> 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
>



-- 
Mark Murphy (a Commons Guy)
http://commonsware.com | http://github.com/commonsguy
http://commonsware.com/blog | http://twitter.com/commonsguy

Android Training in NYC: http://marakana.com/training/android/

-- 
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

Reply via email to