Try using the java keyword "volatile" in you variable declaration.

Al.

On Jul 3, 9:49 am, burtoogle <burtoo...@gmail.com> wrote:
> Hi,
>
> I am starting to develop an Android App and have noticed the following
> behaviour in my test code (not yet designed the real app):
>
> A thread that loops around doing Bluetooth IO accesses an instance
> variable that is declared in the enclosing class. That instance
> variable gets set to null by the GUI thread in the onBackPressed()
> method which also closes the Bluetooth socket which causes an
> exception in the IO thread (which is what I want).
>
> The odd thing is that if I set the instance variable to null before I
> close the socket, the IO thread sees the null value, but if I close
> the socket first and then set the variable to null, the IO thread
> doesn't see the null value.
>
> The instance variable is being used in a loop in the IO thread and it
> appears as if that variable is being cached while within the loop. So
> any changes to that variable by another thread are not visible. Is
> that possible? If so, is there a workaround to guarantee that the VM
> will read the value of the instance variable?
>
> Cheers,
>
> Mark

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

Reply via email to