2010年12月5日星期日

Activity orientation | Activity Restart

The values of Orientation are ORIENTATION_PORTRAIT and
ORIENTATION_LANDSCAPE.


When orientation is changed, the default action is to restart the Activtiy.

If you don’t want your Activity to restart, you should do the following thing:


Config your Activity with the Activity Element
     android:configChanges="keyboardHidden|orientation"
Rewrite the callback method
public void onConfigurationChanged(Configuration newConfig) {
    super.onConfigurationChanged(newConfig);
    if (this.getResources().getConfiguration().orientation ==
    Configuration.ORIENTATION_LANDSCAPE) {
    Log.d(TAG, "++ ORIENTATION_LANDSCAPE ++");
   
    } else if (this.getResources().getConfiguration().orientation
    == Configuration.ORIENTATION_PORTRAIT){
    Log.d(TAG, "++ ORIENTATION_PORTRAIT ++");
    }
}

没有评论: