威海美容网站建设,网站建设部署视频,wordpress如何转换为中文版,长沙做无痛肠镜东大医院l网站在学习Android应用生命周期章节中#xff0c;书本上写的有点笼统#xff0c;较难理解。为了理解的更深#xff0c;写了个程序测试一下。 1、在layout文件夹中建一个dialog_layout.xml ?xml version1.0 encodingutf-8?
LinearLayout x… 在学习Android应用生命周期章节中书本上写的有点笼统较难理解。为了理解的更深写了个程序测试一下。 1、在layout文件夹中建一个dialog_layout.xml ?xml version1.0 encodingutf-8?
LinearLayout xmlns:androidhttp://schemas.android.com/apk/res/androidandroid:layout_widthmatch_parentandroid:layout_heightmatch_parentandroid:orientationvertical TextView android:layout_widthmatch_parentandroid:layout_heightwrap_contentandroid:textThis is a dialog Activity.//LinearLayout 2、在layout文件夹中再建一个normal_layout.xml ?xml version1.0 encodingutf-8?
LinearLayout xmlns:androidhttp://schemas.android.com/apk/res/androidandroid:layout_widthmatch_parentandroid:layout_heightmatch_parentandroid:orientationvertical TextView android:layout_widthmatch_parentandroid:layout_heightwrap_contentandroid:textThis is a normal Activity.//LinearLayout 3、修改layout文件夹中的activity_main.xml ?xml version1.0 encodingutf-8?
LinearLayoutxmlns:androidhttp://schemas.android.com/apk/res/androidandroid:orientationverticalandroid:layout_widthmatch_parentandroid:layout_heightmatch_parentButton android:idid/start_normal_activityandroid:layout_widthmatch_parentandroid:layout_heightwrap_contentandroid:textStart NormalActivity/Button android:idid/start_dialog_activityandroid:layout_widthmatch_parentandroid:layout_heightwrap_contentandroid:textStart DialogActivity/
/LinearLayout4、编写java文件建立一个DialogActivity.java package com.example.acitivitylife;import android.app.Activity;
import android.os.Bundle;public class DialogActivity extends Activity {Overrideprotected void onCreate(Bundle savedInstanceState) {super.onCreate(savedInstanceState);setContentView(R.layout.dialog_layout);}
}5、编写java文件建立一个NormalActivity.java package com.example.acitivitylife;import android.app.Activity;
import android.os.Bundle;public class NormalActivity extends Activity {Overrideprotected void onCreate(Bundle savedInstanceState) {super.onCreate(savedInstanceState);setContentView(R.layout.normal_layout);}
}6、修改MainActivity.java package com.example.acitivitylife;import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;public class MainActivity extends Activity {public static final String TAG MainActivity;Overrideprotected void onCreate(Bundle savedInstanceState) {super.onCreate(savedInstanceState);Log.d(TAG, onCreate);setContentView(R.layout.activity_main);Button startNormalActivity (Button)findViewById(R.id.start_normal_activity);Button startDialogActivity (Button)findViewById(R.id.start_dialog_activity);startNormalActivity.setOnClickListener(new OnClickListener() {Overridepublic void onClick(View v) {// TODO Auto-generated method stubIntent intent new Intent(MainActivity.this, NormalActivity.class);startActivity(intent);}});startDialogActivity.setOnClickListener(new OnClickListener() {Overridepublic void onClick(View v) {// TODO Auto-generated method stubIntent intent new Intent(MainActivity.this, DialogActivity.class);startActivity(intent);}});}Overrideprotected void onStart() {super.onStart();Log.d(TAG, OnStart);}Overrideprotected void onResume() {super.onResume();Log.d(TAG, onResume);}Overrideprotected void onPause() {super.onPause();Log.d(TAG, OnPause);}Overrideprotected void onStop() {super.onStop();Log.d(TAG, onStop);}Overrideprotected void onDestroy() {super.onDestroy();Log.d(TAG, onDestroy);}Overrideprotected void onRestart() {super.onRestart();Log.d(TAG, onRestart);}} 以上步骤完成后安装到手机观察LogCat打印出来的消息对生命周期将一目了然。 自动安装到手机后LogCat打印出 点击Start NormalgActivitya按钮后LogCat打印出 按下返回键后LogCat打印出 点击Start DialogActivitya按钮后LogCat打印出 按下返回键后LogCat打印出 退出程序后LogCat打印出 转载于:https://www.cnblogs.com/LGMing/p/4457447.html