星期二, 十月 23, 2012

比如屏幕旋转90度,Configuration Changes

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.




Because of this, some developers decide to handle the configuration changes (like screen orientation changes) themselves.  This is done by adding the "configChanges" attribute to the Activity declaration in AndroidManifest.xml
?
1
2
3
4
5
6
7
<activity android:name=".SomeActivity" android:label="@string/app_name"
  android:configChanges="orientation">
 <intent-filter>
  <action android:name="android.intent.action.MAIN"/>
  <category android:name="android.intent.category.LAUNCHER"/>
 </intent-filter>
</activity>

The "configChanges" attribute tells Android Platform that, some of the config changes will be handled by the activity by themselves. Platform does not need to do any special handling for these.

Android Configuration change.

http://developer.android.com/guide/topics/resources/runtime-changes.html

In Android, a configuration change causes the current activity to go away and be recreated.
The application itself keeps on running, but it has the opportunity to change
how the activity is displayed in response to the configuration change.

use onSaveInstanceState(Bundle) to keep state or other runtime data.


root Jelly Bean 4.1.2

root JB 4.1.2

首先必须安装了Android sdk和对应手机的USB驱动。
 android sdk: http://developer.android.com/sdk/index.html
  需要一些工具
 
1.download cmw(ClockworkMod) recover 工具.

 http://www.clockworkmod.com/rommanager
查找对应的设备后面的文件。
Galaxy Nexus 就要下载:
http://download2.clockworkmod.com/recoveries/recovery-clockwork-touch-6.0.1.0-maguro.img

2. download superuser packagae
 http://androidsu.com/superuser/
 下载 Superuser-3.1.3-arm-signed.zip
 
3.连接手机USB,设置为debug模式
   用adb push  Superuser-3.1.3-arm-signed.zip /sdcard/Superuser-3.1.3-arm-
signed.zip
    传送到手机上

4.临时进入cmw recover 并安装superuser 包
 进入window 命令行状态 cmd,进入android sdk安装目录下的android-sdk-windows\
platform-tools目录.
 
  adb reboot bootloader
  fastboot boot recovery-clockwork-touch-6.0.
1.0-maguro.img
 等待3秒出现,安装CMW 安装界面,如果是touch版本,则用手势滚动屏幕,选择安装
  select install zip from sdcard.
  否则用音量上下键移动,电源键确认来选择。
 
 安装完成后,用adb reboot 启动手机即可。