活动(Activity)
学习目标 1、了解Activity的概念 2、掌握Activity的创建和启动方法 3、掌握Activity之间消息传递的方法 4、掌握Activity的生命周期 5、掌握Activity的启动模式 Activity概念 是一种可以包含用户界面的组件,主要用于和用户进行交互 Activity创建和启动方法 首先创建的活动是一个Javaclass类,让它继承AppCompatActivity,创建加载布局,在 AndroidManifest.xml中注册 启动默认进入onCreate方法,setContentView(R.layout.first_layout)设置布局,在活动中启动另一个活动startActivity(new Intent()) Activity之间消息传递的方法 使用Intent在活动之间传递,分为显示Intent和隐式Intent Activity生命周期![](/i/l/?n=22&i=blog/2361582/202211/2361582-20221108202048106-1088980691.png)
![](/i/l/?n=22&i=blog/2361582/202211/2361582-20221108202048107-845011983.png)
1.standard
![](/i/l/?n=22&i=blog/2361582/202211/2361582-20221108202048031-171545624.png)
![](/i/l/?n=22&i=blog/2361582/202211/2361582-20221108202048083-1574171905.png)
2.singleTop
顶部复用,即若该activity在这个栈的顶部再次打开时会再次使用它![](/i/l/?n=22&i=blog/2361582/202211/2361582-20221108202048071-442732472.png)
![](/i/l/?n=22&i=blog/2361582/202211/2361582-20221108202048105-1135867386.png)
3.singleTask
![](/i/l/?n=22&i=blog/2361582/202211/2361582-20221108202048039-1139314658.png)
![](/i/l/?n=22&i=blog/2361582/202211/2361582-20221108202048085-139489348.png)
4.singleInstance
单独存在,打开E时会在一个新的栈里打开![](/i/l/?n=22&i=blog/2361582/202211/2361582-20221108202048034-1928210155.png)
![](/i/l/?n=22&i=blog/2361582/202211/2361582-20221108202048084-1486285784.png)
![](/i/l/?n=22&i=blog/2361582/202211/2361582-20221108202048072-1979198030.png)
![](/i/l/?n=22&i=blog/2361582/202211/2361582-20221108202047997-963110922.png)
![](/i/l/?n=22&i=blog/2361582/202211/2361582-20221108202048069-318791360.png)
![](/i/l/?n=22&i=blog/2361582/202211/2361582-20221108202048080-1253241651.png)
![](/i/l/?n=22&i=blog/2361582/202211/2361582-20221108202048045-490590048.png)
![](/i/l/?n=22&i=blog/2361582/202211/2361582-20221108202048080-1942037006.png)