Sorry, just re-read your original text, it seems that message passing
between threads is the way to go.
Just use two way message passing.

On Thu, Dec 31, 2009 at 12:09 AM, Miguel Morales
<[email protected]> wrote:
> Why not use Thread.wait() and Thread.notify() to communicate with the
> working thread.
> Or perhaps message passing to tell the worker thread to wait until
> further notice.
>
> here's how I would do it, though I'm not sure about wait() and
> notify() since I never use them myself.  But I *think* it would go
> something like this:
>
> /*worker thread class*/
> class MyThread extends Thread
> {
>    Handler mHandler;
>    public static final int DONE_MSG = 123;
>    MyThread(Handler pHandler)
>    {
>        mHandler = pHandler;
>    }
>   �...@override run()
>    {
>        //do something.....
>       Bundle bundle = new Bundle();
>       bundle.putInt("TYPE", DONE_MSG);
>       Message msg = new Message();
>       msg.setData(bundle);
>       mHandler.sendMessage(msg);
> }
>
> /*activity class*/
> private Handler message_handler = new Handler()
> {
>    Bundle bundle = msg.getData();
>    int type = bundle.getInt("TYPE");
>    if ( type == MyThread.DONE_MSG )
>    {
>        //dismiss the dialog...
>        tThread.notify();
>    }
> }
>
> tThread = new MyThread(message_handler);
> tThread.start();
>
> //then from your onClick handler....
> //show the dialog....
> tThread.wait();
>
> On Wed, Dec 30, 2009 at 11:49 PM, swapnil kamble <[email protected]> 
> wrote:
>> Let me reframe my question. My intention is not to block UI thread but to
>> block a thread when AlertDialog is shown till the user provides confirmation
>> response.
>>
>> I have handshake process, where I have to provide an option to user whether
>> to accept/reject and based on that user response I want to return a boolean
>> value. And unless this response is not provided next line should not get
>> executed, just exactly what Windows MessageBox does.
>>
>> Now there are two option to start this handshake process, one either from UI
>> thread i.e. starting from some onclick event listener. But I can't use this
>> way, because I want to block thread until response is not provided(modal
>> dialog). Blocking this thread means blocking whole app. So this way i can't
>> do this.
>>
>> Second option is to spawn a new worker thread and then run handshaking from
>> it, we don't mind blocking non-ui thread. But again problem here is that I
>> can't show AlertDialog from non UI thread.
>>
>> I know there is an option to post message and display AlertDialog from that
>> Handler, but then in that case my thread continues and completes its
>> execution even if user response is not provided which I don't want.
>>
>> On Wed, Dec 30, 2009 at 1:16 PM, Romain Guy <[email protected]> wrote:
>>>
>>> If you block the UI thread, the dialog won't work. The user won't be
>>> able to click it, and it might not even draw at all. So a very bad
>>> idea :)
>>>
>>> On Tue, Dec 29, 2009 at 10:33 PM, Frank Weiss <[email protected]> wrote:
>>> > Just like Treking, I'm puzzled by Swapnil's desire to block the UI
>>> > thread.
>>> > Perhaps if he explained what he does not want the UI thread doing while
>>> > the
>>> > dialog is displayed, would shed light on the issue for all.
>>> >
>>> > On Dec 29, 2009 9:59 PM, "TreKing" <[email protected]> wrote:
>>> >
>>> >> I can put my code in listeners but still I dont want that thread to
>>> >> continue its execution
>>> >
>>> > Which thread? The UI thread? I'm pretty sure you DO want the UI thread
>>> > to
>>> > continue it's execution. Why would you NOT?
>>> > What are you trying to accomplish? I can't think of why you would want
>>> > this
>>> > behavior...
>>> >
>>> >
>>> > -------------------------------------------------------------------------------------------------
>>> > ...
>>> >
>>> > On Wed, Dec 30, 2009 at 12:27 AM, swapnil kamble <[email protected]>
>>> > wrote: > > Thanks for your ...
>>> >
>>> > --
>>> >
>>> > You received this message because you are subscribed to the Google
>>> > Groups
>>> > "Android Developers" group...
>>> >
>>> > --
>>> > 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
>>>
>>>
>>>
>>> --
>>> Romain Guy
>>> Android framework engineer
>>> [email protected]
>>>
>>> Note: please don't send private questions to me, as I don't have time
>>> to provide private support.  All such questions should be posted on
>>> public forums, where I and others can see and answer them
>>>
>>> --
>>> 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
>>
>>
>> --
>> ...Swapnil
>>
>> || Hare Krishna Hare Krishna Krishna Krishna Hare Hare ||
>> || Hare Rama    Hare Rama   Rama   Rama    Hare Hare ||
>>
>> --
>> 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
>
>
>
> --
> The Revolting X Software/Music Production:
> http://diastrofunk.com
>



-- 
The Revolting X Software/Music Production:
http://diastrofunk.com
Blogspot:
http://developingthedream.blogspot.com/
Youtube:
http://www.youtube.com/user/revoltingx
~Isaiah 55:8-9

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