Detailed explanation of Android development activity and fragment

1. Life cycle of activity

1) Multiple activities form an activity stack, and the current activity is at the top of the stack. Let's take a look at the class diagrams of various activity base classes:

After the activity class is defined, when the activity is instantiated and when the methods it contains are called are not decided by the developer, but by the Android system.

Let's take a look at the life cycle of activity:

2. Usage of activity

1) Start and close activity

// 首先需要创建启动的Activity对应的Intent
Intent intent = new Intent(MainActivity.this,TwoActivity.class);

// 启动Activity
startActivity(Intent intent);
startActivityForResult(Intent intent,int requestCode); // requestCode:请求码
//startActivityForResult方法以指定的请求码启动Activity,并通过重写onActivityResult方法获取返回的结果。

// 关闭Activity
finish();
finishActivity(int requestCode);
// finishActivity方法结束以startActivityForResult方法启动的Activity。

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>