6.2
今日学习总结
学习时间1.5h代码如下
package com.app.chapter04;
import android.content.ComponentName;
import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import androidx.activity.EdgeToEdge;
import androidx.appcompat.app.AppCompatActivity;
import androidx.core.graphics.Insets;
import androidx.core.view.ViewCompat;
import androidx.core.view.WindowInsetsCompat;
public class ActStartActivity extends AppCompatActivity implements View.OnClickListener {
private static final String TAG ="ning";
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Log.d(TAG,"ActStartActivity onCreate");
EdgeToEdge.enable(this);
setContentView(R.layout.activity_act_start);
findViewById(R.id.btn_act_next).setOnClickListener(this);
}
@Override
public void onClick(View v) {
// 1.在Intent的构造函数中指定
// Intent intent = new Intent(this,ActFinishActivity.class);
//
// 2.调用意图对象的setClass方法指定
// Intent intent =new Intent();
// intent.setClass(this,ActFinishActivity.class);
//
//3.调用意图对象的setComponent方法指定
Intent intent = new Intent();
ComponentName component =new ComponentName(this,ActFinishActivity.class);
intent.setComponent(component);
startActivity(intent);
}
@Override
protected void onStart() {
super.onStart();
Log.d(TAG,"ActStartActivity onStart");
}
@Override
protected void onResume() {
super.onResume();
Log.d(TAG,"ActStartActivity onResume");
}
@Override
protected void onPause() {
super.onPause();
Log.d(TAG,"ActStartActivity onPause");
}
@Override
protected void onStop() {
super.onStop();
Log.d(TAG,"ActStartActivity onStop");
}
@Override
protected void onDestroy() {
super.onDestroy();
Log.d(TAG,"ActStartActivity onDestroy");
}
}
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/main"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".ActStartActivity"
android:orientation="vertical"
android:background="@drawable/becautiful01"
android:gravity="center">
<Button
android:id="@+id/btn_act_next"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="跳转到下一个界面"/>