Android Activity生命周期
来源:互联网 发布:网页编程html 编辑:程序博客网 时间:2024/05/29 09:21
- /**Activity1的代码*/
- public class Activity1 extends Activity {
- private static final String TAG = "Activity1";
- @Override
- public void onCreate(Bundle savedInstanceState) {
- Log.i(TAG, "Activity1 onCreate called!");
- super.onCreate(savedInstanceState);
- setContentView(R.layout.main);
- }
- @Override
- protected void onStart() {
- Log.i(TAG, "Activity1 onStart called!");
- super.onStart();
- }
- @Override
- protected void onRestart() {
- Log.i(TAG, "Activity1 onRestart called!");
- super.onRestart();
- }
- @Override
- protected void onResume() {
- Log.i(TAG, "Activity1 onResume called!");
- super.onResume();
- }
- @Override
- protected void onPause() {
- Log.i(TAG, "Activity1 onPause called!");
- super.onPause();
- }
- @Override
- protected void onStop() {
- Log.i(TAG, "Activity1 onStop called!");
- super.onStop();
- }
- @Override
- protected void onDestroy() {
- Log.i(TAG, "Activity1 onDestroy called!");
- super.onDestroy();
- }
- /**当点击屏幕时,进入Activity2*/
- @Override
- public boolean onTouchEvent(MotionEvent event) {
- Intent intent = new Intent(this, Activity2.class);
- startActivity(intent);
- return super.onTouchEvent(event);
- }
- }
- /**Activity2的代码*/
- public class Activity2 extends Activity {
- private static final String TAG = "Activity2";
- public void onCreate(Bundle savedInstanceState) {
- Log.i(TAG, "Activity2 onCreate called!");
- setContentView(R.layout.main2);
- super.onCreate(savedInstanceState);
- }
- @Override
- protected void onStart() {
- Log.i(TAG, "Activity2 onStart called!");
- super.onStart();
- }
- @Override
- protected void onRestart() {
- Log.i(TAG, "Activity2 onRestart called!");
- super.onRestart();
- }
- @Override
- protected void onResume() {
- Log.i(TAG, "Activity2 onResume called!");
- super.onResume();
- }
- @Override
- protected void onPause() {
- Log.i(TAG, "Activity2 onPause called!");
- super.onPause();
- }
- @Override
- protected void onStop() {
- Log.i(TAG, "Activity2 onStop called!");
- super.onStop();
- }
- @Override
- protected void onDestroy() {
- Log.i(TAG, "Activity2 onDestroy called!");
- super.onDestroy();
- }
- }
- <?xml version="1.0" encoding="utf-8"?>
- <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
- android:orientation="vertical"
- android:layout_width="fill_parent"
- android:layout_height="fill_parent"
- >
- <TextView
- android:layout_width="fill_parent"
- android:layout_height="wrap_content"
- android:text="Hello World, Activity1"
- />
- <EditText
- android:layout_width="fill_parent"
- android:layout_height="50sp"
- />
- </LinearLayout>
- <activity android:name=".Activity2"
- android:label="Activity2"
- android:theme="@android:style/Theme.Dialog"/>
- @Override
- public boolean onTouchEvent(MotionEvent event) {
- //启动一个AlertDialog
- new AlertDialog.Builder(this).setTitle("hello dialog!").show();
- return super.onTouchEvent(event);
- }
从Log信息可以看出,当启动和退出Dialog时,Activity的状态始终未变,可见,Dialog实际上属于Acitivity内部的界面,不会影响Acitivty的生命周期。
0 0
- 【Android】【Activity生命周期】Activity生命周期
- Android activity的生命周期
- Android Activity 生命周期
- Android:Activity的生命周期
- Android 之 Activity 生命周期
- Android Activity生命周期
- android之activity生命周期
- Android Activity生命周期总结
- Android 之 Activity 生命周期
- Android Activity的生命周期
- Android Activity的生命周期
- android中的activity生命周期
- Android---Activity生命周期状态
- Android中Activity生命周期
- Android Activity的生命周期
- Android activity的生命周期
- Android---Activity生命周期状态
- Android---Activity生命周期状态
- spring工作机制及为什么要用?
- java多线程: wait/notify机制
- 一个“鸡血班”毕业生的自述
- hdu 1079 Calendar Game 博弈论
- CCJumpBy函数 CCMoveTo函数的调试 对比
- Android Activity生命周期
- win7中将窗口拉到屏幕边界,窗口自动在竖直方向上平铺的现象
- POJ 1274 The Perfect Stall || POJ 1469 COURSES(zoj 1140)二分图匹配
- 支持多平台!2D和3D游戏引擎Godot宣布开源
- 九度oj 题目1341:艾薇儿的演唱会
- [An AC a day]1160_HDU_ACM
- js把字符串转化为对象、数组
- 20人就能做大型网游 Hero游戏引擎进军韩国
- PB9.0和.INI文件