Life Cycle problem!

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

Life Cycle problem!

Postby skul3r » Fri Jul 03, 2009 2:16 pm

Hi,

I'm having some problems with android's life cycle. When I open the flip of my g1, my application restarts... it is going through all the life cycle: calling onStop, onDestroy, onCreate and etc... does have any way to disable this lyfe cycle when i open the flip of my phone?
skul3r
Freshman
Freshman
 
Posts: 8
Joined: Fri Jul 03, 2009 2:04 pm

Top

Postby cadlg » Fri Jul 03, 2009 2:55 pm

This is from the Official documentation for the Activity class:

Configuration Changes
If the configuration of the device (as defined by the Resources.Configuration class) changes, then anything displaying a user interface will need to update to match that configuration. Because Activity is the primary mechanism for interacting with the user, it includes special support for handling configuration changes.

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

This is done because any application resource, including layout files, can change based on any configuration value. Thus the only safe way to handle a configuration change is to re-retrieve all resources, including layouts, drawables, and strings. Because activities must already know how to save their state and re-create themselves from that state, this is a convenient way to have an activity restart itself with a new configuration.

In some special cases, you may want to bypass restarting of your activity based on one or more types of configuration changes. This is done with the android:configChanges attribute in its manifest. For any types of configuration changes you say that you handle there, you will receive a call to your current activity's onConfigurationChanged(Configuration) method instead of being restarted. If a configuration change involves any that you do not handle, however, the activity will still be restarted and onConfigurationChanged(Configuration) will not be called.


Have a look at the above link.
cadlg
Experienced Developer
Experienced Developer
 
Posts: 84
Joined: Wed Feb 20, 2008 12:33 am
Location: Guatemala

problem solved!

Postby skul3r » Fri Jul 03, 2009 3:46 pm

thank you very much cadlg!
skul3r
Freshman
Freshman
 
Posts: 8
Joined: Fri Jul 03, 2009 2:04 pm

Top

Return to View, Layout & Resource Problems

Who is online

Users browsing this forum: No registered users and 4 guests