[android-developers] Re: Changing a Back button press to Home button press

2009-09-03 Thread Ne0

Dianne,

If there is a more appropriate way of doing this please advise.

My activity, starts, stops and binds to a service. When the activity
is focused, it receives text from the service it is bound to. When
ever the user navigates away from the activity all the currently
received text is saved in onSaveInstanceState() so it can be displayed
once again when focus returns. Though if the back button is used, it
does not get called ( is this correct? ). The user must never be able
to stop activity running without selecting stop from the activity
menu, which in turn stops the service and calls finish().

Liam

On Sep 2, 5:53 pm, Dianne Hackborn hack...@android.com wrote:
 On Wed, Sep 2, 2009 at 2:19 AM, Ne0 liamjamesalf...@googlemail.com wrote:
  Yes that is what i want to achieve and i know it is acting in a non-
  standard way. Please correct me if you think i am going about this in
  the wrong way, but my understanding is that using the back button
  destroys the focused activity and hence does not hit
  onSaveInstanceState(...). The users of this application will be
  expecting it to return to its saved instance state the next time they
  start the activity, unless they use the apps menu to stop the app
  running.

 No they won't expect this, because that is not how android works.  And there
 is certainly not an apps menu menu for them to stop apps.

 Please don't try to make your application behave in a way you think it
 should from some other environment.  It should behave consistently with the
 android UI model, wherever appropriate.

 --
 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: Changing a Back button press to Home button press

2009-09-03 Thread Dianne Hackborn
We've already been having this discussion in another thread.  If you want to
retain some state in your activity -- even across the user pressing back to
finish your activity and then later launching it again -- then just save
that state, in whatever way you want, in onPause().

If you want to let the user have some background thing of your app going on
while the user is not in its UI, you can have in your UI a facility for them
to explicitly start and stop the background work.  That is not the same as
them quitting your app.

On Thu, Sep 3, 2009 at 1:09 AM, Ne0 liamjamesalf...@googlemail.com wrote:


 Dianne,

 If there is a more appropriate way of doing this please advise.

 My activity, starts, stops and binds to a service. When the activity
 is focused, it receives text from the service it is bound to. When
 ever the user navigates away from the activity all the currently
 received text is saved in onSaveInstanceState() so it can be displayed
 once again when focus returns. Though if the back button is used, it
 does not get called ( is this correct? ). The user must never be able
 to stop activity running without selecting stop from the activity
 menu, which in turn stops the service and calls finish().

 Liam

 On Sep 2, 5:53 pm, Dianne Hackborn hack...@android.com wrote:
  On Wed, Sep 2, 2009 at 2:19 AM, Ne0 liamjamesalf...@googlemail.com
 wrote:
   Yes that is what i want to achieve and i know it is acting in a non-
   standard way. Please correct me if you think i am going about this in
   the wrong way, but my understanding is that using the back button
   destroys the focused activity and hence does not hit
   onSaveInstanceState(...). The users of this application will be
   expecting it to return to its saved instance state the next time they
   start the activity, unless they use the apps menu to stop the app
   running.
 
  No they won't expect this, because that is not how android works.  And
 there
  is certainly not an apps menu menu for them to stop apps.
 
  Please don't try to make your application behave in a way you think it
  should from some other environment.  It should behave consistently with
 the
  android UI model, wherever appropriate.
 
  --
  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.
 



-- 
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: Changing a Back button press to Home button press

2009-09-03 Thread Marco Nelissen

See 
http://developer.android.com/reference/android/app/Activity.html#onSaveInstanceState(android.os.Bundle)
for an explanation of why onSaveInstanceState is not called in your
use case.
You should save your state somewhere else, like in onPause()



On Thu, Sep 3, 2009 at 1:09 AM, Ne0liamjamesalf...@googlemail.com wrote:

 Dianne,

 If there is a more appropriate way of doing this please advise.

 My activity, starts, stops and binds to a service. When the activity
 is focused, it receives text from the service it is bound to. When
 ever the user navigates away from the activity all the currently
 received text is saved in onSaveInstanceState() so it can be displayed
 once again when focus returns. Though if the back button is used, it
 does not get called ( is this correct? ). The user must never be able
 to stop activity running without selecting stop from the activity
 menu, which in turn stops the service and calls finish().

 Liam

 On Sep 2, 5:53 pm, Dianne Hackborn hack...@android.com wrote:
 On Wed, Sep 2, 2009 at 2:19 AM, Ne0 liamjamesalf...@googlemail.com wrote:
  Yes that is what i want to achieve and i know it is acting in a non-
  standard way. Please correct me if you think i am going about this in
  the wrong way, but my understanding is that using the back button
  destroys the focused activity and hence does not hit
  onSaveInstanceState(...). The users of this application will be
  expecting it to return to its saved instance state the next time they
  start the activity, unless they use the apps menu to stop the app
  running.

 No they won't expect this, because that is not how android works.  And there
 is certainly not an apps menu menu for them to stop apps.

 Please don't try to make your application behave in a way you think it
 should from some other environment.  It should behave consistently with the
 android UI model, wherever appropriate.

 --
 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: Changing a Back button press to Home button press

2009-09-02 Thread Ne0

Yes that is what i want to achieve and i know it is acting in a non-
standard way. Please correct me if you think i am going about this in
the wrong way, but my understanding is that using the back button
destroys the focused activity and hence does not hit
onSaveInstanceState(...). The users of this application will be
expecting it to return to its saved instance state the next time they
start the activity, unless they use the apps menu to stop the app
running.

Does this mean there is a Home activity then? Do you have any info
about obtaining the Context for this activity so i can launch it?

Liam

On Sep 1, 5:39 pm, Marco Nelissen marc...@android.com wrote:
 Couldn't you just 'eat' the back key, and use startActivity() to
 launch home when you receive it? That should pretty much give you the
 effect the effect you're looking for.
 Of course, then your app is behaving in a nonstandard way, which might
 confuse users, so you should ask yourself whether this is really what
 you want to do.

 On Tue, Sep 1, 2009 at 8:21 AM, Ne0liamjamesalf...@googlemail.com wrote:

  Trying to the do as the title describes with the following code, but
  it doesn't seem to work. It just does nothing once i have altered the
  keyCode. Do i have to do something to the event?

  public boolean onKeyDown(int keyCode, KeyEvent event) {
         /*
          *  The back key usually destroys the activity
          *  without saving the instance. We want the
          *  instance saved if the activity gets destroyed
          *  so we are pretending its a home key press.
          */

         if(gLOG){Log.d(TAG,onKeyDown);}
         if(keyCode == KeyEvent.KEYCODE_BACK){
                 if(gLOG){Log.d(TAG,KEYCODE_BACK  + keyCode);}

                 keyCode = KeyEvent.KEYCODE_HOME;
         }
         return super.onKeyDown(keyCode, event);
     }

  Thanks for any help.

  Liam


--~--~-~--~~~---~--~~
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: Changing a Back button press to Home button press

2009-09-02 Thread Dianne Hackborn
On Wed, Sep 2, 2009 at 2:19 AM, Ne0 liamjamesalf...@googlemail.com wrote:

 Yes that is what i want to achieve and i know it is acting in a non-
 standard way. Please correct me if you think i am going about this in
 the wrong way, but my understanding is that using the back button
 destroys the focused activity and hence does not hit
 onSaveInstanceState(...). The users of this application will be
 expecting it to return to its saved instance state the next time they
 start the activity, unless they use the apps menu to stop the app
 running.


No they won't expect this, because that is not how android works.  And there
is certainly not an apps menu menu for them to stop apps.

Please don't try to make your application behave in a way you think it
should from some other environment.  It should behave consistently with the
android UI model, wherever appropriate.

-- 
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: Changing a Back button press to Home button press

2009-09-01 Thread Romain Guy

This won't work. You just cannot do this.

On Tue, Sep 1, 2009 at 8:21 AM, Ne0liamjamesalf...@googlemail.com wrote:

 Trying to the do as the title describes with the following code, but
 it doesn't seem to work. It just does nothing once i have altered the
 keyCode. Do i have to do something to the event?

 public boolean onKeyDown(int keyCode, KeyEvent event) {
        /*
         *  The back key usually destroys the activity
         *  without saving the instance. We want the
         *  instance saved if the activity gets destroyed
         *  so we are pretending its a home key press.
         */

        if(gLOG){Log.d(TAG,onKeyDown);}
        if(keyCode == KeyEvent.KEYCODE_BACK){
                if(gLOG){Log.d(TAG,KEYCODE_BACK  + keyCode);}

                keyCode = KeyEvent.KEYCODE_HOME;
        }
        return super.onKeyDown(keyCode, event);
    }

 Thanks for any help.

 Liam
 




-- 
Romain Guy
Android framework engineer
romain...@android.com

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 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: Changing a Back button press to Home button press

2009-09-01 Thread Marco Nelissen

Couldn't you just 'eat' the back key, and use startActivity() to
launch home when you receive it? That should pretty much give you the
effect the effect you're looking for.
Of course, then your app is behaving in a nonstandard way, which might
confuse users, so you should ask yourself whether this is really what
you want to do.



On Tue, Sep 1, 2009 at 8:21 AM, Ne0liamjamesalf...@googlemail.com wrote:

 Trying to the do as the title describes with the following code, but
 it doesn't seem to work. It just does nothing once i have altered the
 keyCode. Do i have to do something to the event?

 public boolean onKeyDown(int keyCode, KeyEvent event) {
        /*
         *  The back key usually destroys the activity
         *  without saving the instance. We want the
         *  instance saved if the activity gets destroyed
         *  so we are pretending its a home key press.
         */

        if(gLOG){Log.d(TAG,onKeyDown);}
        if(keyCode == KeyEvent.KEYCODE_BACK){
                if(gLOG){Log.d(TAG,KEYCODE_BACK  + keyCode);}

                keyCode = KeyEvent.KEYCODE_HOME;
        }
        return super.onKeyDown(keyCode, event);
    }

 Thanks for any help.

 Liam
 


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