第20天android:《android从零开始》视频(89)

8.Activity生命周期

1.Log类的简单实用

Log.v(String tag,String msg);

tag在过滤显示的时候实用,建议tag为一个常量,一般为类名。

v:verbose,d:debug,i:info,w:warn,e:error

2.activity的生命周期

官方文档位置:docs/guide/topics/fundamentals/activities.html

3.将activity打开为一个窗口

在AndroidManifest.xml里:

<activity
            android:name=".A1Activity"
            android:label="@string/app_name"
            android:theme="@android:style/Theme.Dialog">
</activity>

4.各个状态:

onPause 要做一些信息的简单保存,不宜做耗时操作。

适合做一些持久化操作。

9.Activity高级学习

1.存储状态

使用,在destory这个activity的时候,下面的方法不执行。

//会在OnStop 之前执行,和OnPause的同时执行(或前或后)。
protect void onSaveInstanceStat(Bundle outState){
     outState.putString("key","value");
}

//取出来
public void onCreate(Bundle savedInstanceState){
     print savedInstanceState.getString("key");
}

2.android主题

android:theme="@android:style/Theme.Black"//背景变黑

android:theme="@android:style/Theme.Light"//背景变白

android:theme="@android:style/Theme.Light.Panel"

android:theme="@android:style/Theme.Panel"//只显示控件

android:theme="@android:style/Theme.Translucent"//透明

android:theme="@android:style/Theme.Wallpaper"//使用壁纸

android:theme="@android:style/Theme.Wallpaper.NoTitleBar"//使用壁纸

android:theme="@android:style/Theme.Wallpaper.NoTitleBar.Fullscreen"//使用壁纸

android:theme="@android:style/Theme.Dialog"

原文地址:https://www.cnblogs.com/wanself/p/2806485.html