[android-developers] Re: Handler and MessageQueue question

2009-04-06 Thread Taísa Cristina
Yes, it helps me a lot!
I was really confused about that.

Thanks, Greg!  ;)


On Sat, Apr 4, 2009 at 4:37 AM, Greg Krimer gkri...@gmail.com wrote:


 Hi Taísa,

 I am reversing the order of your questions.

  Did you say the main thread has its own handler?! So, if mine no more
  exists, the it will handle that message?

 As Dianne said, your handler is not associated with the activity. The
 behavior of your handler is not influenced by the state of the
 activity in which it was created. The handler does not know or care
 that the activity is finished. Instead, the handler is associated with
 the messages that are destined for it. When you create a message and
 send it to some handler, a reference to the handler is placed into the
 target field of the message. So long as there are messages in the
 queue with your handler as the target, your handler will be called to
 service them. When there are no more messages in the queue whose
 target is your handler then, assuming there are no references to your
 handler anywhere else, your handler will be garbage collected like all
 normal objects. There is no magical link between your handler and the
 activity.

  So, it's not ugly to finish my Activity and let that message in the
  MessageQueue of the main thread? :)

 It is not ugly, but it may or may not be what you want. It depends on
 the action that the message triggers. I had just this same situation.
 In my case, the message after the killer message would have
 triggered an action that is not valid once the activity is finished.
 Since there is no magic link between the handler and the activity I
 had to make one: I implemented handleMessage() in such a way that it
 dropped messages if the activity was finished.

 In your case, if the message after the killer message is handled
 harmlessly when the activity is finished then you don't need to do
 anything special about it. Just leave it in the queue and it let your
 handler take care of it.

 Hope this helps.

 Greg

 On Apr 3, 11:31 am, Taísa Cristina taisa.san...@gmail.com wrote:
 
  On Fri, Apr 3, 2009 at 3:21 PM, Dianne Hackborn hack...@android.com
 wrote:
   Provided your process doesn't get killed, your process's main thread
 will
   handle that message whenever it comes up, regardless of what happened
 to the
   activity.  Handler doesn't know anything about the activity state.
 
 
 
 
 
 
   On Fri, Apr 3, 2009 at 11:17 AM, Taísa Cristina 
 taisa.san...@gmail.comwrote:
 
   Hi all,
 
   I have a Handler implementation that is used in my Activity.
 
   While handling the messages, there's a value of msg.what which makes
 my
   Activity to finish itself.
 
   My problem is that, when that killer message arrives, there's
 another
   one in the message queue also destined to my handler.
 
   In this case, what happens if I just finish my Activity?
 
   I could see that no exception raised.  But, who will handle this lost
   message since its Handler no longer exists?
 
   ** I have another Activity receiving messages containing the same data
 as
   the killer one. So, [ I think ] I can't use removeMessage(what,
 obj).
 
   Taísa
 
   --
   Dianne Hackborn
   Android framework engineer
   hack...@android.com
 
   Note: please don't send private questions to me, as I don't have time
 to
   provide private support, and so won't reply to such e-mails.  All such
   questions should be posted on public forums, where I and others can see
 and
   answer them.
 
  --
  Taísa Cristina Costa dos Santos
  Computer Engineer
  Brazil, SP
  55 19 8152-7453
 



-- 
Taísa Cristina Costa dos Santos
Computer Engineer
Brazil, SP
55 19 8152-7453

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



[android-developers] Re: Handler and MessageQueue question

2009-04-04 Thread Greg Krimer

Hi Taísa,

I am reversing the order of your questions.

 Did you say the main thread has its own handler?! So, if mine no more
 exists, the it will handle that message?

As Dianne said, your handler is not associated with the activity. The
behavior of your handler is not influenced by the state of the
activity in which it was created. The handler does not know or care
that the activity is finished. Instead, the handler is associated with
the messages that are destined for it. When you create a message and
send it to some handler, a reference to the handler is placed into the
target field of the message. So long as there are messages in the
queue with your handler as the target, your handler will be called to
service them. When there are no more messages in the queue whose
target is your handler then, assuming there are no references to your
handler anywhere else, your handler will be garbage collected like all
normal objects. There is no magical link between your handler and the
activity.

 So, it's not ugly to finish my Activity and let that message in the
 MessageQueue of the main thread? :)

It is not ugly, but it may or may not be what you want. It depends on
the action that the message triggers. I had just this same situation.
In my case, the message after the killer message would have
triggered an action that is not valid once the activity is finished.
Since there is no magic link between the handler and the activity I
had to make one: I implemented handleMessage() in such a way that it
dropped messages if the activity was finished.

In your case, if the message after the killer message is handled
harmlessly when the activity is finished then you don't need to do
anything special about it. Just leave it in the queue and it let your
handler take care of it.

Hope this helps.

Greg

On Apr 3, 11:31 am, Taísa Cristina taisa.san...@gmail.com wrote:

 On Fri, Apr 3, 2009 at 3:21 PM, Dianne Hackborn hack...@android.com wrote:
  Provided your process doesn't get killed, your process's main thread will
  handle that message whenever it comes up, regardless of what happened to the
  activity.  Handler doesn't know anything about the activity state.






  On Fri, Apr 3, 2009 at 11:17 AM, Taísa Cristina 
  taisa.san...@gmail.comwrote:

  Hi all,

  I have a Handler implementation that is used in my Activity.

  While handling the messages, there's a value of msg.what which makes my
  Activity to finish itself.

  My problem is that, when that killer message arrives, there's another
  one in the message queue also destined to my handler.

  In this case, what happens if I just finish my Activity?

  I could see that no exception raised.  But, who will handle this lost
  message since its Handler no longer exists?

  ** I have another Activity receiving messages containing the same data as
  the killer one. So, [ I think ] I can't use removeMessage(what, obj).

  Taísa

  --
  Dianne Hackborn
  Android framework engineer
  hack...@android.com

  Note: please don't send private questions to me, as I don't have time to
  provide private support, and so won't reply to such e-mails.  All such
  questions should be posted on public forums, where I and others can see and
  answer them.

 --
 Taísa Cristina Costa dos Santos
 Computer Engineer
 Brazil, SP
 55 19 8152-7453
--~--~-~--~~~---~--~~
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
-~--~~~~--~~--~--~---



[android-developers] Re: Handler and MessageQueue question

2009-04-03 Thread Dianne Hackborn
Provided your process doesn't get killed, your process's main thread will
handle that message whenever it comes up, regardless of what happened to the
activity.  Handler doesn't know anything about the activity state.

On Fri, Apr 3, 2009 at 11:17 AM, Taísa Cristina taisa.san...@gmail.comwrote:

 Hi all,

 I have a Handler implementation that is used in my Activity.

 While handling the messages, there's a value of msg.what which makes my
 Activity to finish itself.

 My problem is that, when that killer message arrives, there's another one
 in the message queue also destined to my handler.

 In this case, what happens if I just finish my Activity?

 I could see that no exception raised.  But, who will handle this lost
 message since its Handler no longer exists?

 ** I have another Activity receiving messages containing the same data as
 the killer one. So, [ I think ] I can't use removeMessage(what, obj).

 Taísa

 



-- 
Dianne Hackborn
Android framework engineer
hack...@android.com

Note: please don't send private questions to me, as I don't have time to
provide private support, and so won't reply to such e-mails.  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 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
-~--~~~~--~~--~--~---



[android-developers] Re: Handler and MessageQueue question

2009-04-03 Thread Taísa Cristina
So, it's not ugly to finish my Activity and let that message in the
MessageQueue of the main thread? :)

On Fri, Apr 3, 2009 at 3:21 PM, Dianne Hackborn hack...@android.com wrote:

 Provided your process doesn't get killed, your process's main thread will
 handle that message whenever it comes up, regardless of what happened to the
 activity.  Handler doesn't know anything about the activity state.


Did you say the main thread has its own handler?! So, if mine no more
exists, the it will handle that message?



 On Fri, Apr 3, 2009 at 11:17 AM, Taísa Cristina taisa.san...@gmail.comwrote:

 Hi all,

 I have a Handler implementation that is used in my Activity.

 While handling the messages, there's a value of msg.what which makes my
 Activity to finish itself.

 My problem is that, when that killer message arrives, there's another
 one in the message queue also destined to my handler.

 In this case, what happens if I just finish my Activity?

 I could see that no exception raised.  But, who will handle this lost
 message since its Handler no longer exists?

 ** I have another Activity receiving messages containing the same data as
 the killer one. So, [ I think ] I can't use removeMessage(what, obj).

 Taísa





 --
 Dianne Hackborn
 Android framework engineer
 hack...@android.com

 Note: please don't send private questions to me, as I don't have time to
 provide private support, and so won't reply to such e-mails.  All such
 questions should be posted on public forums, where I and others can see and
 answer them.


 



-- 
Taísa Cristina Costa dos Santos
Computer Engineer
Brazil, SP
55 19 8152-7453

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