项目 ActivityLife
layout部分:
activity_01.xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".Activity01">
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:onClick="click"
android:text="开启Activity02"/>
</RelativeLayout>
activity_02.xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".Activity02">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:text="Hello World!"/>
</RelativeLayout>
java代码部分:
Activity01.java
package com.example.hzg.activity;
import android.content.Intent;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
public class Activity01 extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_01);
Log.i("Activity01","onCreate()");
}
protected void onStart() {
super.onStart();
Log.i("Activity01","onStart()");
}
protected void onRestart(){
super.onRestart();
Log.i("Activity01","onRestart()");
}
protected void onResume(){
super.onResume();
Log.i("Activity01","onResume()");
}
protected void onPause(){
super.onPause();
Log.i("Activity01","onPause()");
}
protected void onStop(){
super.onStop();
Log.i("Activity01","onStop()");
}
protected void onDestroy(){
super.onDestroy();
Log.i("Activity01","onDestroy()");
}
public void click(View view){
Intent intent=new Intent(this,Activity02.class);
startActivity(intent);
}
}
activity02.java
package com.example.hzg.activity;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.util.Log;
public class Activity02 extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_02);
Log.i("Activity02","onCreate()");
}
protected void onStart(){
super.onStart();
Log.i("Activity02","onStart()");
}
protected void onRestart(){
super.onRestart();
Log.i("Activity02","onRestart()");
}
protected void onResume(){
super.onResume();
Log.i("Activity02","onResume()");
}
protected void onPause(){
super.onPause();
Log.i("Activity02","onPause()");
}
protected void onStop(){
super.onStop();
Log.i("Activity02","onStop()");
}
protected void onDestroy(){
super.onDestroy();
Log.i("Activity02","onDestroy()");
}
}