1.生命周期//使Activity用弹出窗的形式显示
//配置AndroidManifest.xml中的Activity android:theme="@android:style/Theme.Dialog" 1.Log类 Log.v(String tag,String msg);//VERBOSE Log.d(String tag,String msg);//DEBUG Log.i(String tag,String msg);//INFO Log.w(String tag,String msg);//WARN Log.e(String tag,String msg);//ERROR 2.Activity生命周期 a)假设有二个Activity,分别名为:OneActivity,TwoActivity OneActivity的生命周期为: OnCreate(Bundle saveInstanceState) onStart(); onResume(); //调用TwoActivity,则执行 onPause(); //如果此时OneActivity不可见,则会执行 onStop(); //如果从TwoActivity返回到OneActivity,则执行 onRestart(),onStart() //如果此时OneActivity可见,则不执行onStop(); //如果从TwoActivity返回到OneActivity,则执行 onResume(); //退出的时候 onDestory();
2.高级使用:
1.比如,如果正在文件框加输入信息,此时有电话进来的话,接电话时, Activity会进入不可视的状态,即会调用onStop()方法。 而且,如果此时Android系统资源欠缺的话,就会结束掉Activity. 所以,处理这种情况呢? 方法: onSaveInstancesState(Bundle outState){ super.onSaveInstancesState(outState); } 此方法会在onStop() 或 onPause() 之前执行 用来保存一些状态。 保存的信息会存放在Bundle中(Bundle有点类似JAVA中的MAP) Bundle是Android来安排的,所以,如果Activity被杀掉,此 Bundle还是存在的。 例: onSaveInstancesState(Bundle outState){ super.onSaveInstancesState(outState); ..... String text = ......... outState.putString(String name,String value); } onCreate(Bundle savedInstanceState){ .........//判断Bundle不为空,且存在值 obj.setText(.....); .......... }
Theme
2. Android:theme //Activity弹出窗显示 android:theme="@android:style/Theme.Dialog" //不显示TitleBar android:theme="@android:style/Theme.NoTitleBar" //程序显示满整个屏幕 android:theme="@android:style/Theme.NoTitleBar.Fullscreen" //白色背景 android:theme="Theme.Light" android:theme="Theme.Light.NoTitleBar" android:theme="Theme.Light.NoTitleBar.Fullscreen" //黑色背景 android:theme="Theme.Black" android:theme="Theme.Black.NoTitleBar" android:theme="Theme.Black.NoTitleBar.Fullscreen" //将程序的背景同壁纸是一致的 android:theme="Theme.Wallpaper" android:theme="Theme.Wallpaper.NoTitleBar" android:theme="Theme.Wallpaper.NoTitleBar.Fullscreen" //背景透明度 android:theme="Translucent" android:theme="Theme.Translucent.NoTitleBar" android:theme="Theme.Translucent.NoTitleBar.Fullscreen" //只显示文本框,按钮等 android:theme="Theme.Panel" android:theme="Theme.Light.Panel"