首页
JAVA笔记
数据库笔记
混乱记忆
小站记
您现在的位置
android切换状态
简介: 记录android应用在切换过程中各种状态--create、start、create、start、resume、SaveInstanceState、pause、stop、destroy、create、start、RestoreInstanceState的关系

布局:
LinearLayout,AbsoluteLayout,RelativeLayout,FrameLayout,TableLayout

 

按钮控件:
Button,ImageButton,ToggleButton,

输入控件:
EditText


显示视图控件:
TextView,ImageView,


动作:
alpha<!-- 透明度的变换 -->
scale<!-- 尺寸的变换 -->
translate<!-- 尺位置的变换 -->
rotate<!-- 旋转变换 -->


通信:
Handler + Message,继承BroadcastReceiver(示例请看3_6)

启动新的activity:
Intent

文件读写:
在activity中可调用openFileInput和openFileOutput拿到文件流
getResources().openRawResource()可拿raw资源目录。
getResources().getAssets().open(fileName)可拿assets资源目录

数据库操作:
继承重写SQLiteOpenHelper 的onCreate() 可实现表初始化
使用SQLiteDatabase的方法可实现数据操作


保存数据:
SharedPreferences:可以用来保存部分数据

http请求:
URL+URLConnection+文件流

google地图:(详见 5_4)
 MapView myMapView = null;//声明MapView的引用
 MapController myMapController = null;//声明myMapController的引用
 LocationManager mLocationManager = null;
        mLocationManager = (LocationManager)getSystemService(Context.LOCATION_SERVICE);

 

未知:RecognitionService


样式:
android 中可以使用定义的样式。
android:theme="@android:style/Theme.NoTitleBar.Fullscreen"

 


实例化layout配置文件:
LayoutInflater 对象可以实例化xml配置文件。
LayoutInflater.from(context)..inflate(R.layout.list_item_icon_text, null);--返回一个R.layout.list_item_icon_text对应的view

 

另外getSystemService()是Android很重要的一个API,它是Activity的一个方法,根据传入的NAME来取得对应的Object,然后转换成相应的服务对象。以下介绍系统相应的服务。

传入的Name  返回的对象  说明
WINDOW_SERVICE  WindowManager  管理打开的窗口程序
LAYOUT_INFLATER_SERVICE  LayoutInflater  取得xml里定义的view
ACTIVITY_SERVICE  ActivityManager  管理应用程序的系统状态
POWER_SERVICE PowerManger  电源的服务
ALARM_SERVICE  AlarmManager  闹钟的服务
NOTIFICATION_SERVICE  NotificationManager  状态栏的服务
KEYGUARD_SERVICE  KeyguardManager  键盘锁的服务
LOCATION_SERVICE  LocationManager  位置的服务,如GPS
SEARCH_SERVICE  SearchManager  搜索的服务
VEBRATOR_SERVICE  Vebrator  手机震动的服务
CONNECTIVITY_SERVICE  Connectivity  网络连接的服务
WIFI_SERVICE  WifiManager  Wi-Fi服务
TELEPHONY_SERVICE  TeleponyManager  电话服务

 

 

 

 

 

 

activity 特性:
不设置任何属性:启动时执行
06-16 16:21:23.178: INFO/System.out(1074): create main
06-16 16:21:23.288: INFO/System.out(1074): start main
06-16 16:21:23.288: INFO/System.out(1074): resume main

设置屏幕横屏方式启动:activity中设置: setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
--启动时 会启动后马上注销,然后再启动,需要特别注意。
06-16 21:05:46.225: INFO/System.out(4363): create
06-16 21:05:46.365: INFO/System.out(4363): start
06-16 21:05:46.365: INFO/System.out(4363): resume
06-16 21:05:46.395: INFO/System.out(4363): SaveInstanceState
06-16 21:05:46.395: INFO/System.out(4363): pause
06-16 21:05:46.395: INFO/System.out(4363): stop
06-16 21:05:46.395: INFO/System.out(4363): destroy
06-16 21:05:46.705: INFO/System.out(4363): create
06-16 21:05:46.845: INFO/System.out(4363): start
06-16 21:05:46.855: INFO/System.out(4363): RestoreInstanceState
06-16 21:05:46.865: INFO/System.out(4363): resume
06-16 21:05:46.935: INFO/ActivityManager(131): Displayed activity com.lihuige/.MainMenuActivity: 993 ms (total 993 ms)

 

不设置任何属性:退出时执行
06-16 19:39:27.415: INFO/System.out(3997): SaveInstanceState
06-16 19:39:27.415: INFO/System.out(3997): Pause
06-16 19:39:27.455: WARN/InputManagerService(131): Ignoring hideSoftInput of: com.android.internal.view.IInputMethodClient$Stub$Proxy@43edf6a8
06-16 19:39:27.665: INFO/System.out(3997): stop


不设置任何属性:退出后再进入时执行
06-16 19:39:33.185: INFO/ActivityManager(131): Starting activity: Intent { act=android.intent.action.MAIN cat=[android.intent.category.LAUNCHER] flg=0x10200000 cmp=com.lihuige/.Start }
06-16 19:39:33.245: INFO/System.out(3997): restart
06-16 19:39:33.245: INFO/System.out(3997): start
06-16 19:39:33.245: INFO/System.out(3997): resume


设置横纵屏切换特性后退出后再进入时执行:设置方式在AndroidManifest.xml 设置activity 属性 android:configChanges="orientation|keyboardHidden"
--执行结果同上

 


不设置任何属性:跳转到子activity
06-16 16:42:52.108: INFO/ActivityManager(131): Starting activity: Intent { cmp=com.lihuige/.MainFrame (has extras) } --被启动的activity
06-16 16:42:52.128: INFO/System.out(1867): SaveInstanceState 
06-16 16:42:52.138: INFO/System.out(1867): Pause
06-16 16:42:52.158: INFO/System.out(1867): create main --子activity中的方法
06-16 16:42:52.248: INFO/System.out(1867): start main --子activity中的方法
06-16 16:42:52.258: INFO/System.out(1867): resume main --子activity中的方法
06-16 16:42:52.318: INFO/onWindowFocusChanged(1867): onWindowFocusChangedtrue --子activity中的方法
06-16 16:42:52.358: INFO/com.lihuige.frame.Layer.ActiveLayer(1867): surfaceCreated --子activity中的控件
06-16 16:42:52.358: INFO/com.lihuige.frame.Layer.ActiveLayer(1867): surfaceChanged --子activity中的控件
06-16 16:42:52.408: INFO/ActivityManager(131): Displayed activity com.lihuige/.MainFrame: 268 ms (total 268 ms) --显示子activity
06-16 16:42:52.418: INFO/System.out(1867): stop

 

 

不设置任何属性:从子activity反回
06-16 16:33:08.888: INFO/System.out(1074): pause main --子activity中的方法
06-16 16:33:08.908: INFO/System.out(1074): restart
06-16 16:33:08.908: INFO/System.out(1074): start
06-16 16:33:08.908: INFO/System.out(1074): resume
06-16 16:33:09.148: INFO/com.lihuige.frame.Layer.ActiveLayer(1074): surfaceDestroyed --子activity中的控件
06-16 16:33:10.328: INFO/System.out(1074): stop main --子activity中的方法
06-16 16:33:10.328: INFO/System.out(1074): destroy main --子activity中的方法

 


设置横纵屏切换特性后从子activity反回:设置方式在AndroidManifest.xml 设置activity 属性 android:configChanges="orientation|keyboardHidden"
--执行结果同上

 

 

不设置任何属性:横纵屏切换
06-16 16:54:03.038: INFO/System.out(2112): SaveInstanceState main --保存当前状态
06-16 16:54:03.148: INFO/System.out(2112): pause main
06-16 16:54:03.148: INFO/System.out(2112): stop main
06-16 16:54:03.148: INFO/System.out(2112): destroy main
06-16 16:54:03.148: INFO/com.lihuige.dialog.CustomDialog(2112):  dialog stop --注销子控件
06-16 16:54:03.158: INFO/com.lihuige.frame.Layer.ActiveLayer(2112): surfaceDestroyed --注销子控件
06-16 16:54:03.188: INFO/System.out(2112): create main
06-16 16:54:03.248: INFO/System.out(2112): start main
06-16 16:54:03.268: INFO/System.out(2112): RestoreInstanceState main
06-16 16:54:03.268: INFO/System.out(2112): resume main
06-16 16:54:03.368: INFO/onWindowFocusChanged(2112): onWindowFocusChangedtrue
06-16 16:54:03.438: INFO/com.lihuige.frame.Layer.ActiveLayer(2112): surfaceCreated
06-16 16:54:03.438: INFO/com.lihuige.frame.Layer.ActiveLayer(2112): surfaceChanged


设置横纵屏切换特性: 设置方式在AndroidManifest.xml 设置activity 属性 android:configChanges="orientation|keyboardHidden"
切换横纵屏后 回调 onConfigurationChanged

 


不设置任何属性:超时黑屏
---黑屏阶段
06-16 17:03:31.048: INFO/System.out(2404): SaveInstanceState
06-16 17:03:31.048: INFO/System.out(2404): Pause
---亮屏阶段
06-16 17:03:32.538: INFO/System.out(2404): resume

 

不设置任何属性:超时锁屏
----黑屏阶段
06-16 17:00:22.508: INFO/System.out(2404): SaveInstanceState
06-16 17:00:22.508: INFO/System.out(2404): Pause

 

设置屏幕横屏方式启动:activity中设置: setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);   ---锁屏后会注销当前activity并重启一个新的activity
----黑屏阶段
06-16 17:00:22.508: INFO/System.out(2404): SaveInstanceState
06-16 17:00:22.508: INFO/System.out(2404): Pause
----锁屏阶段
06-16 17:00:22.588: DEBUG/ConnectivityService(131): receive screen off intent!
06-16 17:00:22.598: DEBUG/ConnectivityService(131): getMobileDataEnabled returning false
06-16 17:00:22.618: DEBUG/QCRIL_MSC(75): "RIL"=>"AMSS" [ label = "cm_mm_client_ss_reg()"];
06-16 17:00:22.618: DEBUG/QCRIL_MSC(75): "RIL"=>"AMSS" [ label = "cm_mm_client_ss_reg()"];
06-16 17:00:27.778: DEBUG/StatusBar(131): DISABLE_EXPAND: yes
06-16 17:00:27.848: INFO/WindowManager(131): Setting rotation to 0, animFlags=1
06-16 17:00:27.868: INFO/ActivityManager(131): Config changed: { scale=1.0 imsi=460/1 loc=zh_CN touch=3 keys=1/1/2 nav=3/1 orien=1 layout=18 uiMode=17 seq=53}
06-16 17:00:27.998: INFO/System.out(2404): stop
06-16 17:00:27.998: INFO/System.out(2404): destroy
06-16 17:00:28.388: INFO/System.out(2404): create
06-16 17:00:28.558: INFO/System.out(2404): start
06-16 17:00:28.578: INFO/System.out(2404): RestoreInstanceState
06-16 17:00:28.578: INFO/System.out(2404): resume
06-16 17:00:28.598: INFO/System.out(2404): Pause

 

设置横纵屏切换特性后超时锁屏: 设置方式在AndroidManifest.xml 设置activity 属性 android:configChanges="orientation|keyboardHidden"
06-16 17:14:08.498: INFO/System.out(2637): SaveInstanceState --当前 activity 方法
06-16 17:14:08.498: INFO/System.out(2637): Pause --当前 activity 方法
06-16 17:14:08.588: DEBUG/ConnectivityService(131): receive screen off intent!
06-16 17:14:08.588: DEBUG/ConnectivityService(131): getMobileDataEnabled returning false
06-16 17:14:08.618: DEBUG/QCRIL_MSC(75): "RIL"=>"AMSS" [ label = "cm_mm_client_ss_reg()"];
06-16 17:14:08.618: DEBUG/QCRIL_MSC(75): "RIL"=>"AMSS" [ label = "cm_mm_client_ss_reg()"];
06-16 17:14:13.758: DEBUG/StatusBar(131): DISABLE_EXPAND: yes
06-16 17:14:13.828: INFO/WindowManager(131): Setting rotation to 0, animFlags=1
06-16 17:14:13.848: INFO/ActivityManager(131): Config changed: { scale=1.0 imsi=460/1 loc=zh_CN touch=3 keys=1/1/2 nav=3/1 orien=1 layout=18 uiMode=17 seq=63}

 

不设置任何属性屏幕解锁:
06-16 22:24:09.105: INFO/System.out(4467): resume


设置横纵屏切换特性方式启动,锁屏后解锁: 设置方式在AndroidManifest.xml 设置activity 属性 android:configChanges="orientation|keyboardHidden"
--同上


设置屏幕横屏方式启动,锁屏后解锁:activity中设置: setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);

06-16 21:25:15.735: INFO/System.out(4363): resume ---当前 activity中的方法
06-16 21:25:15.825: DEBUG/ConnectivityService(131): receive screen on intent!
06-16 21:25:15.825: DEBUG/ConnectivityService(131): stop powersaving action!
06-16 21:25:15.825: DEBUG/ConnectivityService(131): setMobileDataEnabled(true)
06-16 21:25:15.825: DEBUG/ConnectivityService(131): getMobileDataEnabled returning true
06-16 21:25:15.855: DEBUG/WallpaperManager(131): getWallpaperCid() file not exists!
06-16 21:25:15.885: DEBUG/QCRIL_MSC(75): "RIL"=>"AMSS" [ label = "cm_mm_client_ss_reg()"];
06-16 21:25:15.885: DEBUG/QCRIL_MSC(75): "RIL"=>"AMSS" [ label = "cm_mm_client_ss_reg()"];
06-16 21:25:15.885: DEBUG/QCRIL_MSC(75): "RIL"=>"AMSS" [ label = "cm_ss_cmd_get_ss_info()"];
06-16 21:25:15.975: DEBUG/QCRIL_MSC(75): "RIL"=>"AMSS" [ label = "cm_ph_cmd_get_ph_info()"];
06-16 21:25:15.995: DEBUG/GsmServiceStateTracker(205): handlePollStateResult  regplmn = 46001
06-16 21:25:16.755: ERROR/Sensors(131): light: -1 lux
06-16 21:25:16.755: ERROR/Sensors(608): light: -1 lux
06-16 21:25:17.315: DEBUG/KeyguardViewMediator(131): pokeWakelock(10000)
06-16 21:25:17.415: DEBUG/KeyguardViewMediator(131): pokeWakelock(10000)
06-16 21:25:17.475: INFO/WindowManager(131): Setting rotation to 1, animFlags=1
06-16 21:25:17.495: INFO/ActivityManager(131): Config changed: { scale=1.0 imsi=460/1 loc=zh_CN touch=3 keys=1/1/2 nav=3/1 orien=2 layout=18 uiMode=17 seq=116}
06-16 21:25:17.615: INFO/System.out(4363): SaveInstanceState   ---当前 activity中的方法
06-16 21:25:17.615: INFO/System.out(4363): pause   ---当前 activity中的方法
06-16 21:25:17.615: INFO/System.out(4363): stop  ---当前 activity中的方法
06-16 21:25:17.615: INFO/System.out(4363): destroy  ---当前 activity中的方法
06-16 21:25:17.625: INFO/UsageStats(131): Unexpected resume of com.lihuige while already resumed in com.lihuige
06-16 21:25:17.825: ERROR/Sensors(131): light: 640 lux
06-16 21:25:17.825: ERROR/Sensors(608): light: 640 lux
06-16 21:25:17.945: INFO/System.out(4363): create  ---当前 activity中的方法
06-16 21:25:18.065: INFO/System.out(4363): start  ---当前 activity中的方法
06-16 21:25:18.065: INFO/System.out(4363): RestoreInstanceState  ---当前 activity中的方法
06-16 21:25:18.065: INFO/System.out(4363): resume  ---当前 activity中的方法

 

 


android 2.2  bug 收录
1:
 设置AndroidManifest.xml中的 activityandroid:configChanges="orientation|keyboardHidden"
        android:configChanges="orientation|keyboardHidden" 的作用是翻转屏幕时不 重新创建新的activity。
        如果这时再在activity中设置setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
 那么在activity中弹出dialog后 通过按键锁屏,在屏幕解锁时出现卡住!
 以上屏幕卡住原因:只要dialog 在onPause方法中show 的时候才会卡住!


 

最近更新