2014-05-21 20:02 GMT+04:00 plnelson <pna...@gmail.com>:

> On Tuesday, May 20, 2014 11:51:35 PM UTC-4, Jonathan S wrote:
>>
>> Can you copy and paste code in the *MyRemoteActivity class?*
>>>
>>
>>     It's 700 lines of (mostly proprietary) code, so no I don't think that
> would be practical.    Anyway,* my questions are generic Android
> questions*; they're not specific to the code:   I'm not asking for anyone
> to debug this for me; I'm just trying to understand more so I can debug it
> myself.
>
> 1. * If it's the wrong thread then why does the stack trace show the same
> thread in the cases where it crashes and where it doesn't?*
> ...in other words what does Android mean by "wrong thread"?  If the
> debugger shows it executing in the same thread when it's not crashing as
> when it lands in the catch block with the "wrong thread" then what exactly
> do they mean by "wrong thread"?
>

Is there more to the message? I grepped the "base" framework, and came up
with these:

./core/tests/coretests/src/android/widget/focus/RequestFocusTest.java:
 // Test that a requestFocus from the wrong thread fails.
./core/tests/coretests/src/android/widget/focus/RequestFocusTest.java:
       fail("requestFocus from wrong thread should raise exception.");
./opengl/java/android/opengl/ManagedEGLContext.java:            throw new
IllegalStateException("Called on wrong thread");
./opengl/java/android/opengl/GLErrorWrapper.java:
 "OpenGL method called from wrong thread.");

Two of these are in tests.


>
>
> *And what does the Eclipse debugger thread nomenclature ( "Thread x[
> Thread-y]" ) mean?*
> The Eclipse debugger seems to refer to a thread 9 and a thread 10.   What
> does the debugger mean when it displays it that way?
>

They're just thread ids (the "x") and auto-generated thread names.

When you debug in Eclipse, you should see other threads with more
meaningful names, e.g. "main", "Binder_x", etc.

You can assign names to your threads by calling Thread.setName. Personally,
I find it very useful for debugging and postmortem crash reports:

http://developer.android.com/reference/java/lang/Thread.html#setName(java.lang.String)


>
>
> *What are some good strategies for analyzing "wrong thread" bugs? *
> Just that -  what tools or strategies are recommended to see what code is
> executing in which threads - how do experienced Android programmers debug
> these kinds of exceptions?
>

Not sure I qualify as an "experienced" Android programmer, but...

...

>From your original description (I snipped it, it was below), it seems you
have some code that runs on a worker thread, and yet is placed in a file
called MyRemoteActivity.

There is nothing wrong with naming source files anything you wish, but ---
is that actually an Android activity?

Are you sure the code in that file, that runs on a non-main thread, does
not make any calls to Android UI code?

Conversely, your code should not be making networking calls on the main
thread. You can use StrictMode to log such events:

http://developer.android.com/reference/android/os/StrictMode.html

And going back to your original message again:

"the other one is the main thread that handles all the usual View stuff"

Do you mean the "main" Android thread that get pre-created for you, or do
you mean there is a different thread that your code creates (and which
you're calling "main") that interacts with the Android UI framework?

You should only call Android UI framework methods from the "main" thread
that gets pre-created for you by Android, that's the thread on which all
component callbacks are called (onCreate, etc.).

-- K

-- 
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en
--- 
You received this message because you are subscribed to the Google Groups 
"Android Developers" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to android-developers+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to