Re: [android-developers] Re: How can I know when the home button has been pressed?

2011-06-15 Thread eyasu getahun
Hello Kostya,

Please help me if you have any idea where to decrypt the encrypted sms
message. I have encrypted the sms under onclick method. But I don't know
where to decrypt it at time of delivery to the receiver. I am using android
emulator not on real phone devices. Please let me know your idea. Thanks!.

On Sun, Jun 12, 2011 at 11:03 AM, Kostya Vasilyev kmans...@gmail.comwrote:

 I didn't say anything about a thread - in fact, my recommendation is to not
 use a thread just for scheduling stuff (although that Thread.sleep() can
 look so tempting...).

 As for Handler messages not firing when there aren't any activities on the
 screen - that's simply not true.

 The event loop continues to run. There may not be any messages to deliver,
 but the loop is there ready to do work if needed, just like Binder threads.

 I posted a simple test a couple of months ago that showed this.

 In fact, that's how component callbacks are delivered, including those to
 services and receivers.

 -- Kostya
 2011/6/12 Indicator Veritatis mej1...@yahoo.com

 O...K..., now that we have that clarification, is there anytime that
 the Activity will be paused or stopped (i.e. onPause(), onStop()
 called) when you DO want the timer thread to fire anyway? If the
 answer is 'no', then follow Kostya's suggestion, killing the thread in
 either onPause() or onStop(). If the answer is 'yes', then things get
 more complicated: I suggest putting the timer thread in a Service, not
 an Activity, sending a message to the UI Thread when it fires. Then
 that Thread will display only when it is in the foreground. But then
 you will probably want special logic to handle stale messages when the
 UI Thread executes onResume(). After all, sendMessageAtTime() and
 sendMessageDelayed enqueue the message at that time: they make no
 guarantees about when the Handler Thread will finally actually -
 process- the message. If the Thread has all activities paused, then
 that will be delayed until the right Activity gets an onResume()
 callback.

 On Jun 11, 4:15 am, Droid rod...@gmail.com wrote:
  Thanks for your sensible suggestion. My sentence should have read 'I
  have a timer thread that should not bring an activity back to view
  after the home button has been pressed but it does.'
 
  On Jun 11, 1:02 am, Indicator Veritatis mej1...@yahoo.com wrote:
 
   @Droid-
 
   You do realize, I hope, since it is the level of logic that should be
   easily expected of any programmer, that what you wrote here makes no
   sense.
 
   If, after all, on the one hand, My thread is a timer thread that
   brings my activity back to view after
   thehome buttonis pressed. then no, it makes NO sense to cancel it
   whenhome buttonis pressed.
 
   Besides: if it is a timer thread, shouldn't you really mean that it
   bring your activity back to view after the timer expires? It would
   make sense to cancel that timer when Home is pressed. And you can do
   that in onPause() or in onStop(). In fact, you should probably do that
   in onStop() no matter how you get there This would also simplify your
   code, since it is by design that the platform does not TELL you how
   you got to onStop(): it certainly does not tell you that it got there
   via a Home key.
 
   Also as has been pointed out many times now, overriding the expected
   result of the Home key is a really, REALLY bad idea. It is a good
   thing that the platform makes this difficult. It should not be done at
   all.
 
   Now I realize that some customers insist on this 'feature', even
   though it is such a bad idea. In which case, I pity you, but keep on
   slogging ahead. It is possible to get close to what you want, either
   with a custom Home application or some even more kludgy approach. But
   ignore Fung's suggestion, since he is dead wrong.
 
   On Jun 10, 8:52 am, Droid rod...@gmail.com wrote:
 
My thread is a timer thread that brings my activity back to view
 after
thehome buttonis pressed. I need to cancel it whenhome buttonis
pressed.
(I have 10 activities and no idea in which activity the app was when
thehome buttonwas pressed)
 
On Jun 8, 1:23 pm, TreKing treking...@gmail.com wrote:
 
 On Wed, Jun 8, 2011 at 1:34 AM, Droid rod...@gmail.com wrote:
  I have a thread that needs specifically to be cancelled when the
 home buttonis pressed.
 
 Perhaps if you explain why you think your thread needs to be
 specifically
 canceled on pressing Home you can get an answer that helps you fix
 your
 actual problem and not hack around it.
 

 ---
 --
 TreKing http://sites.google.com/site/rezmobileapps/treking -
 Chicago
 transit tracking app for Android-powered devices

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

Re: [android-developers] Re: How can I know when the home button has been pressed?

2011-06-12 Thread Kostya Vasilyev
I didn't say anything about a thread - in fact, my recommendation is to not
use a thread just for scheduling stuff (although that Thread.sleep() can
look so tempting...).

As for Handler messages not firing when there aren't any activities on the
screen - that's simply not true.

The event loop continues to run. There may not be any messages to deliver,
but the loop is there ready to do work if needed, just like Binder threads.

I posted a simple test a couple of months ago that showed this.

In fact, that's how component callbacks are delivered, including those to
services and receivers.

-- Kostya
2011/6/12 Indicator Veritatis mej1...@yahoo.com

 O...K..., now that we have that clarification, is there anytime that
 the Activity will be paused or stopped (i.e. onPause(), onStop()
 called) when you DO want the timer thread to fire anyway? If the
 answer is 'no', then follow Kostya's suggestion, killing the thread in
 either onPause() or onStop(). If the answer is 'yes', then things get
 more complicated: I suggest putting the timer thread in a Service, not
 an Activity, sending a message to the UI Thread when it fires. Then
 that Thread will display only when it is in the foreground. But then
 you will probably want special logic to handle stale messages when the
 UI Thread executes onResume(). After all, sendMessageAtTime() and
 sendMessageDelayed enqueue the message at that time: they make no
 guarantees about when the Handler Thread will finally actually -
 process- the message. If the Thread has all activities paused, then
 that will be delayed until the right Activity gets an onResume()
 callback.

 On Jun 11, 4:15 am, Droid rod...@gmail.com wrote:
  Thanks for your sensible suggestion. My sentence should have read 'I
  have a timer thread that should not bring an activity back to view
  after the home button has been pressed but it does.'
 
  On Jun 11, 1:02 am, Indicator Veritatis mej1...@yahoo.com wrote:
 
   @Droid-
 
   You do realize, I hope, since it is the level of logic that should be
   easily expected of any programmer, that what you wrote here makes no
   sense.
 
   If, after all, on the one hand, My thread is a timer thread that
   brings my activity back to view after
   thehome buttonis pressed. then no, it makes NO sense to cancel it
   whenhome buttonis pressed.
 
   Besides: if it is a timer thread, shouldn't you really mean that it
   bring your activity back to view after the timer expires? It would
   make sense to cancel that timer when Home is pressed. And you can do
   that in onPause() or in onStop(). In fact, you should probably do that
   in onStop() no matter how you get there This would also simplify your
   code, since it is by design that the platform does not TELL you how
   you got to onStop(): it certainly does not tell you that it got there
   via a Home key.
 
   Also as has been pointed out many times now, overriding the expected
   result of the Home key is a really, REALLY bad idea. It is a good
   thing that the platform makes this difficult. It should not be done at
   all.
 
   Now I realize that some customers insist on this 'feature', even
   though it is such a bad idea. In which case, I pity you, but keep on
   slogging ahead. It is possible to get close to what you want, either
   with a custom Home application or some even more kludgy approach. But
   ignore Fung's suggestion, since he is dead wrong.
 
   On Jun 10, 8:52 am, Droid rod...@gmail.com wrote:
 
My thread is a timer thread that brings my activity back to view
 after
thehome buttonis pressed. I need to cancel it whenhome buttonis
pressed.
(I have 10 activities and no idea in which activity the app was when
thehome buttonwas pressed)
 
On Jun 8, 1:23 pm, TreKing treking...@gmail.com wrote:
 
 On Wed, Jun 8, 2011 at 1:34 AM, Droid rod...@gmail.com wrote:
  I have a thread that needs specifically to be cancelled when the
 home buttonis pressed.
 
 Perhaps if you explain why you think your thread needs to be
 specifically
 canceled on pressing Home you can get an answer that helps you fix
 your
 actual problem and not hack around it.
 

 ---
 --
 TreKing http://sites.google.com/site/rezmobileapps/treking -
 Chicago
 transit tracking app for Android-powered devices

 --
 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 post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email 

Re: [android-developers] Re: How can I know when the home button has been pressed?

2011-06-11 Thread Kostya Vasilyev
You don't need a thread *just* to schedule an event. There is an easier way,
which should also fit your number of activities better.

1 - This needs to be done in the code for each of your activities. Use a
base class, or a delegate object.

2 - In onCreate, make a Handler object with an anonymous inner Callback
(just like for setOnClickListener).

http://developer.android.com/reference/android/os/Handler.html#Handler(android.os.Handler.Callback
)

3 - Define a what constant for a special message, which will be used by
this Handler. Doesn't have to be a system-wide unique, in fact a zero will
do.

4 - When you want to schedule a delayed task, do this:

mHandler.sendEmptyMessageAtTime or mHandler.sendEmptyMessageDelayed with the
what constant defined above.

http://developer.android.com/reference/android/os/Handler.html#sendMessageAtTime(android.os.Message,
long)

5 - In the handler's callback, check the what of the message, and do
whatever needs to be done.

6 - In the activity's onPause or onStop, call this to remove all pending
messages with that what value from the event queue:

http://developer.android.com/reference/android/os/Handler.html#removeMessages(int
)

If the operation you're going to perform needs an argument, obtain a message
using this:

http://developer.android.com/reference/android/os/Handler.html#obtainMessage(int,
java.lang.Object)

and post with this:

http://developer.android.com/reference/android/os/Handler.html#sendMessageAtTime(android.os.Message,
long)

or sendMessageDelayed

-- Kostya
2011/6/11 Droid rod...@gmail.com

 Thanks for your sensible suggestion. My sentence should have read 'I
 have a timer thread that should not bring an activity back to view
 after the home button has been pressed but it does.'


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

Re: [android-developers] Re: How can I know when the home button has been pressed?

2011-06-11 Thread Simon Jackson
But he probly needs to make a political irritation screen for the department 
of grope safety. With a casino link.

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

Re: [android-developers] Re: How can I know when the home button has been pressed?

2011-06-10 Thread TreKing
On Wed, Jun 8, 2011 at 2:01 AM, Andy Fung tsf...@gmail.com wrote:

 if(keyCode == KeyEvent.KEYCODE_HOME)


http://developer.android.com/reference/android/view/KeyEvent.html#KEYCODE_HOME

This key is handled by the framework and is never delivered to
applications.

Please read the documentation, test your code, and verify it actually works
before posting misinformation.

-
TreKing http://sites.google.com/site/rezmobileapps/treking - Chicago
transit tracking app for Android-powered devices

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

Re: [android-developers] Re: How can I know when the home button has been pressed?

2011-06-10 Thread TreKing
On Fri, Jun 10, 2011 at 10:52 AM, Droid rod...@gmail.com wrote:

 My thread is a timer thread that brings my activity back to view after the
 home button is pressed.

I need to cancel it when home button is pressed.


Let me get this straight - I run your app then press Home to do something
else, then at some random point you pop yourself back up on my screen? Uh
... why?

I'm sorry but none of this makes any sense to me.

-
TreKing http://sites.google.com/site/rezmobileapps/treking - Chicago
transit tracking app for Android-powered devices

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

Re: [android-developers] Re: How can I know when the home button has been pressed?

2011-06-10 Thread rich friedel
To add to that you are also saying that while using your app I might have to 
go back through 9 activities to get to my home screen??? Then on top of that 
you want to disable the home button, my only means of NOT going through 9 
potential activities *obviously I could also pull the battery*

You might wish to reconsider your programming techniques!

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

Re: [android-developers] Re: How can I know when the home button has been pressed?

2011-06-10 Thread Kostya Vasilyev
No sense pulling the battery if the application also intercepts
boot_completed :)



2011/6/10 rich friedel rich.frie...@gmail.com

 To add to that you are also saying that while using your app I might have
 to go back through 9 activities to get to my home screen??? Then on top of
 that you want to disable the home button, my only means of NOT going through
 9 potential activities *obviously I could also pull the battery*

 You might wish to reconsider your programming techniques!

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

Re: [android-developers] Re: How can I know when the home button has been pressed?

2011-06-10 Thread rich friedel
Argggh You sir are evil LOL :)

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