ThinkChat🤖让你学习和工作更高效,注册即送10W Token,即刻开启你的AI之旅 广告
#### **创建一个 Activity** 在 android 中创建一个 Activity 是很简单的事情,编写一个继承自 android.app.Activity的 Java 类并在 AndroidManifest.xml声明即可。 ~~~ public class CurrentActivity extends Activity { protected void onCreate(Bundle savedInstanceState); protected void onStart(); protected void onResume(); protected void onPause(); protected void onStop(); protected void onDestroy(); } ///AndroidManifest.xml <activity android:name="com.xxx.xx.ui.CurrentActivity" /> ~~~ #### **启动另外一个 Activity** Activity.startActivity()方法可以根据传入的参数启动另外一个 Activity: ~~~ Intent intent =new Intent(CurrentActivity.this,OtherActivity.class); startActivity(intent); ~~~ #### **Activity 之间通信** 使用 Intent 通信 Android 中通过 Intent 对象来表示一条消息,一个 Intent 对象不仅包含有这个消息的目的地,还可以包含消息的内容,这好比一封 Email,其中不仅应该包含收件地址,还可以包含具体的内容。对于一个 Intent 对象,消息“目的地”是必须的,而内容则是可选项。 ~~~ Intent intent =new Intent(CurrentActivity.this,OtherActivity.class); // 创建一个带“收件人地址”的 email Bundle bundle =new Bundle();// 创建 email 内容 bundle.putBoolean("boolean_key", true);// 编写内容 bundle.putString("string_key", "string_value"); intent.putExtra("key", bundle);// 封装 email startActivity(intent);// 启动新的 Activity ~~~ ### Activity生命周期 ![](https://box.kancloud.cn/5fbd28f1a459a8e220b1a0e0e369da3f_513x663.png) 参考: 1、https://developer.android.google.cn/reference/android/app/Activity.html 2、https://juejin.im/entry/57ad35f67db2a200540c4135