編輯:關於android開發
package com.example.yanlei.yl2;
import android.app.AlertDialog;
import android.content.DialogInterface;
import android.content.DialogInterface.OnKeyListener;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.app.Activity;
import android.os.Bundle;
import android.util.Log;
import android.widget.TextView;
public class MainActivity extends AppCompatActivity {
public static final String TAG = "生命周期:";
String Str = "";
TextView pTextView = null;
@Override
public void onCreate(Bundle savedInstanceState) {
//當創建此Activity的時候回調
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Log.e(TAG, "onCreate");
try {
Str = Str + "創建:\n";
pTextView.setText(Str);
} catch (Exception e) {
//Log.e(TAG, "error : "+e.getMessage(), e);
}
}
@Override
protected void onDestroy() {
//當銷毀此Activity的時候回調
super.onDestroy();
Log.e(TAG, "onDestroy");
try {
Str = Str + "摧毀:\n";
pTextView.setText(Str);
} catch (Exception e) {
//Log.e(TAG, "error : "+e.getMessage(), e);
}
}
@Override
protected void onPause() {
//當暫停此Activity的時候回調
super.onPause();
Log.e(TAG, "onPause");
try {
Str = Str + "暫停:\n";
pTextView.setText(Str);
} catch (Exception e) {
// Log.e(TAG, "error : "+e.getMessage(), e);
}
}
@Override
protected void onRestart() {
//當重新開始此Activity的時候回調
super.onRestart();
Log.e(TAG, "onRestart");
try
{
Str = Str + "重新啟動:\n";
pTextView.setText(Str);
} catch (Exception e) {
//Log.e(TAG, "error : "+e.getMessage(), e);
}
}
@Override
protected void onResume() {
//當顯示展示此Activity的界面的時候回調
super.onResume();
Log.e(TAG, "onResume");
try {
Str = Str + "繼續:\n";
pTextView.setText(Str);
} catch (Exception e) {
//Log.e(TAG, "error : "+e.getMessage(), e);
}
}
@Override
protected void onStart() {
//當使用此Activity可以接受用戶操作的時候回調
super.onStart();
Log.e(TAG, "onStart");
try {
Str = Str + "開始:\n";
pTextView.setText(Str);
} catch (Exception e) {
//Log.e(TAG, "error : "+e.getMessage(), e);
}
}
@Override
protected void onStop() {
//當停止此Activity的時候回調
super.onStop();
Log.e(TAG, "onStop");
try {
Str = Str + "停止:\n";
pTextView.setText(Str);
} catch (Exception e) {
//Log.e(TAG, "error : "+e.getMessage(), e);
}
}
}
日志如下:
onCreate
onStart
onResume
onPause
onStop
onDestroy
Android開發技巧——定制仿微信圖片裁剪控件
Android開發技巧——定制仿微信圖片裁剪控件 拍照——裁剪,或者是選擇圖片——裁剪,是我們設置頭像或上傳圖片時經常
[android] 天氣app布局練習(二),androidapp
[android] 天氣app布局練習(二),androidapp主要練習一下GridView MainActivity.java package com.examp
對話框AlertDialog的基本創建,對話框alertdialog
對話框AlertDialog的基本創建,對話框alertdialog 測試代碼: 布局: <RelativeLayout xmlns:
Android studio使用gradle動態構建APP(不同的包,不同的icon、label),androidgradle
Android studio使用gradle動態構建APP(不同的包,不同的icon、label),androidgradle 最近有個需求,需要做兩個功