Android教程網
  1. 首頁
  2. Android 技術
  3. Android 手機
  4. Android 系統教程
  5. Android 游戲
 Android教程網 >> Android技術 >> Android開發 >> 關於android開發 >> 初識Activity,騰訊視頻初識虛擬化

初識Activity,騰訊視頻初識虛擬化

編輯:關於android開發

初識Activity,騰訊視頻初識虛擬化


CallbackDescription onCreate() This is the first callback and called when the activity is first created. onStart() This callback is called when the activity becomes visible to the user. onResume() This is called when the user starts interacting with the application. onPause() The paused activity does not receive user input and cannot execute any code and called when the current activity is being paused and the previous activity is being resumed. onStop() This callback is called when the activity is no longer visible. onDestroy() This callback is called before the activity is destroyed by the system. onRestart() This callback is called when the activity restarts after stopping it.

關鍵代碼如下:

public class MainActivity extends Activity {
private String msg="Android: ";
/**
* Called when the activity is first created.
*/
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Log.d(msg, "The onCreate() event");
}

/**
* Called when the activity is about to become visible.
*/
@Override
protected void onStart() {
// TODO Auto-generated method stub
super.onStart();
Log.d(msg, "The onStart() event");
}

/**
* Called when the activity has become visible.
*/
@Override
protected void onResume() {
// TODO Auto-generated method stub
super.onResume();
Log.d(msg, "The onResume() event");
}

/**
* Called when another activity is taking focus.
*/
@Override
protected void onPause() {
// TODO Auto-generated method stub
super.onPause();
Log.d(msg, "The onPause() event");
}

/**
* Called when the activity is no longer visible.
*/
@Override
protected void onStop() {
// TODO Auto-generated method stub
super.onStop();
Log.d(msg, "The onStop() event");
}

/**
* Called just before the activity is destroyed.
*/
@Override
protected void onDestroy() {
// TODO Auto-generated method stub
super.onDestroy();
Log.d(msg, "The onDestroy() event");
}
}

 

運行截圖:

當Activity第一次打開時:

當啟動另一個Activity時:

當關閉當前的Activity,返回到先前的Activity時:

當銷毀當前Activity時:

 

  1. 上一頁:
  2. 下一頁:
熱門文章
閱讀排行版
Copyright © Android教程網 All Rights Reserved