Orientation : onStop onDestroy called from BACK key or not ?

Put problem concerning Views, Layouts and other XML-Resources (like AndroidManifest) here.

Orientation : onStop onDestroy called from BACK key or not ?

Postby bsegonnes » Thu Sep 17, 2009 1:09 pm

Hi,

Each time I switch the orientation of the device, onStop() and onDestroy() are called.
They are also called when I close the Avtivity, and when I press 'back' key.

In onStop() or onDestroy() : how can I know how I can here ?

I'd like to run some code when I close the Activity (back button), but not if I change screen orientation.
Bernard Segonnes

http://bsegonnes.free.fr
bsegonnes
Freshman
Freshman
 
Posts: 9
Joined: Fri Jun 19, 2009 1:09 pm
Location: Paris, France

Top

Re: Orientation : onStop onDestroy called from BACK key or n

Postby DavidLau » Fri Oct 16, 2009 1:02 pm

I have the same question :)
bsegonnes wrote:Hi,

Each time I switch the orientation of the device, onStop() and onDestroy() are called.
They are also called when I close the Avtivity, and when I press 'back' key.

In onStop() or onDestroy() : how can I know how I can here ?

I'd like to run some code when I close the Activity (back button), but not if I change screen orientation.
A chinese man
DavidLau
Freshman
Freshman
 
Posts: 3
Joined: Fri Aug 14, 2009 9:31 am

Postby sudheer1437 » Wed Oct 28, 2009 4:24 pm

Hi...
In android sdk 2.0, there is a new method introduced to track the back key presses...
so just have a look at that...
sudheer1437
Experienced Developer
Experienced Developer
 
Posts: 79
Joined: Sat Aug 08, 2009 7:42 am
Location: India

Postby I_Artist » Wed Oct 28, 2009 4:56 pm

Hi,

From the Activity class documentation :

Unless you specify otherwise, a configuration change (such as a change in screen orientation, language, input devices, etc) will cause your current activity to be destroyed, going through the normal activity lifecycle process of onPause(), onStop(), and onDestroy() as appropriate. If the activity had been in the foreground or visible to the user, once onDestroy() is called in that instance then a new instance of the activity will be created, with whatever savedInstanceState the previous instance had generated from onSaveInstanceState(Bundle).

http://developer.android.com/reference/ ... ionChanges

I_Artist
The I_Artist

follow me on Twitter: @I_Artist
follow Android Development on Twitter: #androiddev

Show the world that you are an #androiddev, wear the badge http://www.twibbon.com/join/androiddev
User avatar
I_Artist
Developer
Developer
 
Posts: 33
Joined: Fri Oct 16, 2009 3:49 am
Location: St-Eustache, Quebec

Re: Orientation : onStop onDestroy called from BACK key or n

Postby icobasco » Wed Jan 13, 2010 5:04 pm

bsegonnes wrote:Hi,

In onStop() or onDestroy() : how can I know how I can here ?

I'd like to run some code when I close the Activity (back button), but not if I change screen orientation.


In your activity:

Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1.  
  2.     public boolean onKeyDown(int keyCode, KeyEvent event){
  3.  
  4.                 Log.e(TAG, "Pressed key " + keyCode);
  5.  
  6.        
  7.  
  8.                 if (keyCode == KeyEvent.KEYCODE_BACK){
  9.  
  10.                                   // User pressed BACK: handle it and return true;
  11.  
  12.                 }
  13.  
  14.  
  15.  
  16.                 return false;
  17.  
  18.         }
  19.  
  20.     }
  21.  
  22.  
Parsed in 0.032 seconds, using GeSHi 1.0.8.4
User avatar
icobasco
Senior Developer
Senior Developer
 
Posts: 108
Joined: Thu Jun 04, 2009 11:12 am
Location: Italy

Top

Return to View, Layout & Resource Problems

Who is online

Users browsing this forum: Majestic-12 [Bot], Yahoo [Bot] and 5 guests