Tuesday, August 02, 2011

onDestoy-onCreate kikapcsolasa forgatasnal

Innen

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.


Es ez azert volt erdekes, mert a recorder activity OnCreate-jeben hoztam letre foldereket amiket az onDestroy-ban toroltem, ha nem kellettek, de amig ezt nem kapcsoltam be, addig minden device forgatasnal jott az onDestroy es onCreate.
Ezeknel az eventeknel lehet meg kikapcsolni az automatikus activity ujrainditast:

public static final int configChanges

Specify one or more configuration changes that the activity will handle itself. If not specified, the activity will be restarted if any of these configuration changes happen in the system. Otherwise, the activity will remain running and itsActivity.onConfigurationChanged method called with the new configuration.

Note that all of these configuration changes can impact the resource values seen by the application, so you will generally need to re-retrieve all resources (including view layouts, drawables, etc) to correctly handle any configuration change.

These values must be kept in sync with those in ActivityInfo and include/utils/ResourceTypes.h.

Must be one or more (separated by '|') of the following constant values.

ConstantValueDescription
mcc0x0001The IMSI MCC has changed, that is a SIM has been detected and updated the Mobile Country Code.
mnc0x0002The IMSI MNC has changed, that is a SIM has been detected and updated the Mobile Network Code.
locale0x0004The locale has changed, that is the user has selected a new language that text should be displayed in.
touchscreen0x0008The touchscreen has changed. Should never normally happen.
keyboard0x0010The keyboard type has changed, for example the user has plugged in an external keyboard.
keyboardHidden0x0020The keyboard or navigation accessibility has changed, for example the user has slid the keyboard out to expose it. Note that despite its name, this applied to any accessibility: keyboard or navigation.
navigation0x0040The navigation type has changed. Should never normally happen.
orientation0x0080The screen orientation has changed, that is the user has rotated the device.
screenLayout0x0100The screen layout has changed. This might be caused by a different display being activated.
uiMode0x0200The global user interface mode has changed. For example, going in or out of car mode, night mode changing, etc.
screenSize0x0400The current available screen size has changed. If applications don't target at least HONEYCOMB_MR2 then the activity will always handle this itself (the change will not result in a restart). This represents a change in the currently available size, so will change when the user switches between landscape and portrait.
smallestScreenSize0x0800The physical screen size has changed. If applications don't target at least HONEYCOMB_MR2 then the activity will always handle this itself (the change will not result in a restart). This represents a change in size regardless of orientation, so will only change when the actual physical screen size has changed such as switching to an external display.
fontScale0x40000000The font scaling factor has changed, that is the user has selected a new global font size.

Constant Value: 16842783 (0x0101001f)