zoukankan      html  css  js  c++  java
  • 29、activity横竖屏切换细节问题

     1   import android.app.Activity;
     2 import android.content.Intent;
     3 import android.os.Bundle;
     4 import android.view.View;
     5 
     6 /**
     7  * activity横竖屏切换细节问题。
     8  * @author dr
     9  */
    10 public class DemoActivity extends Activity {
    11 
    12     public void click(View view) {
    13         Intent intent = new Intent(this, Dmeo2Activity.class);
    14         startActivity(intent);
    15     }
    16 
    17     /**
    18      * activity第一次被创建的时候 执行的方法
    19      */
    20     @Override
    21     public void onCreate(Bundle savedInstanceState) {
    22         super.onCreate(savedInstanceState);
    23         setContentView(R.layout.main);
    24         int page = 0;
    25         // pdf 阅读器 当前用户读到了第30页
    26         if (savedInstanceState != null) {
    27             page = savedInstanceState.getInt("page");
    28             System.out.println("定位到 第 " + page + "页");
    29         }
    31         System.out.println("oncreate");
    32     }
    33 
    34     /**
    35      * 在activity被异常 回收的时候 会被执行
    36      */
    37     @Override
    38     protected void onSaveInstanceState(Bundle outState) {
    39         super.onSaveInstanceState(outState);
    40 
    41         outState.putInt("page", 30);
    42     }
    43 
    44     /**
    45      * 用户可见的时候 调用onstart();
    46      */
    47     @Override
    48     protected void onStart() {
    49         // TODO Auto-generated method stub
    50         super.onStart();
    51         System.out.println("onStart");
    52         // System.out.println("判断是否有暂停的位置 ,从暂停的位置继续播放");
    53     }
    54 
    55     @Override
    56     protected void onRestart() {
    57         // TODO Auto-generated method stub
    58         super.onRestart();
    59         System.out.println("onRestart");
    60     }
    61 
    62     @Override
    63     protected void onResume() {
    64         // TODO Auto-generated method stub
    65         super.onResume();
    66         System.out.println("onResume");
    67     }
    68 
    69     @Override
    70     protected void onPause() {
    71         // TODO Auto-generated method stub
    72         super.onPause();
    73         System.out.println("onPause");
    74     }
    75 
    76     @Override
    77     protected void onStop() {
    78         // TODO Auto-generated method stub
    79         // System.out.println("暂停视频播放");
    80         super.onStop();
    81         System.out.println("onStop");
    82     }
    83 
    84     /**
    85      * activity 被销毁的时候 执行的方法
    86      */
    87     @Override
    88     protected void onDestroy() {
    89         // TODO Auto-generated method stub
    90         super.onDestroy();
    91         System.out.println("onDestroy");
    92     }
    93 
    94 }
     1 import android.app.Activity;
     2 import android.os.Bundle;
     3 
     4 public class Dmeo2Activity extends Activity {
     5     /**
     6      * activity第一次被创建的时候 执行的方法
     7      */
     8     @Override
     9     public void onCreate(Bundle savedInstanceState) {
    10         super.onCreate(savedInstanceState);
    11         setContentView(R.layout.main1);
    12         System.out.println("activity02 oncreate");
    13     }
    14 
    15     /**
    16      * activity变成用户可见的时候执行
    17      */
    18     @Override
    19     protected void onStart() {
    20         // TODO Auto-generated method stub
    21         super.onStart();
    22         System.out.println("activity02 onStart");
    23     }
    24 
    25     @Override
    26     protected void onRestart() {
    27         // TODO Auto-generated method stub
    28         super.onRestart();
    29         System.out.println("activity02 onRestart");
    30     }
    31 
    32     /**
    33      * 当界面获取焦点的时候执行的方法 
    34      */
    35     @Override
    36     protected void onResume() {
    37         // TODO Auto-generated method stub
    38         super.onResume();
    39         System.out.println("activity02 onResume");
    40     }
    41 
    42     /**
    43      * 当界面失去焦点的时候 调用的方法 
    44      */
    45     @Override
    46     protected void onPause() {
    47         // TODO Auto-generated method stub
    48         super.onPause();
    49         System.out.println("activity02 onPause");
    50     }
    51 
    52     /**
    53      * 当界面用户不可见的时候 调用的方法 
    54      */
    55     @Override
    56     protected void onStop() {
    57         // TODO Auto-generated method stub
    58         super.onStop();     
    59         System.out.println("activity02 onStop");
    60     }
    61 
    62     /**
    63      * activity 被销毁的时候 执行的方法 
    64      */
    65     @Override
    66     protected void onDestroy() {
    67         // TODO Auto-generated method stub
    68         super.onDestroy();
    69         System.out.println("activity02 onDestroy");
    70     }
    71 }
     1 <?xml version="1.0" encoding="utf-8"?>
     2 <manifest xmlns:android="http://schemas.android.com/apk/res/android"
     3     package="cn.itcast.life"
     4     android:versionCode="1"
     5     android:versionName="1.0" >
     6 
     7     <uses-sdk android:minSdkVersion="8" />
     8 
     9     <application
    10         android:icon="@drawable/ic_launcher"
    11         android:label="@string/app_name" >
    12         <activity
    13             android:name=".DemoActivity"
    14             android:label="@string/app_name" >
    15             <intent-filter>
    16                 <action android:name="android.intent.action.MAIN" />
    17                 <category android:name="android.intent.category.LAUNCHER" />
    18             </intent-filter>
    19         </activity>
    20         
    21         <activity
    22             android:name=".Dmeo2Activity"
    23             android:configChanges="keyboardHidden|orientation"
    24             android:theme="@android:style/Theme.Dialog" />
    25     </application>
    26 
    27 </manifest>
    28 
    29 <!-- 
    30     在切换activity横屏竖屏的时候,不会销毁activity然后去创建新的了。
    31     android:configChanges="keyboardHidden|orientation"
    32  -->
  • 相关阅读:
    Spring事务(三)事务增强器
    Spring事务(二)事务自定义标签
    Spring事务(一)JDBC方式下的事务使用示例
    Spring整合MyBatis(五)MapperScannerConfigurer
    Spring整合MyBatis(四)MapperFactoryBean 的创建
    BOS物流管理系统-第五天
    BOS物流管理系统-第一天
    SSM
    【剑指offer】翻转单词顺序,C++实现
    【特征选择】嵌入式特征选择法
  • 原文地址:https://www.cnblogs.com/androidsj/p/3966013.html
Copyright © 2011-2022 走看看