零基礎Android學習筆記-02 安卓程序生命週期

一個安卓程序生命週期會經歷7中狀態,並不必定是每次都所有經歷。Create,Start,ReStart,Pause,Resume,Stop,Destory.ide

重載方法,用helloWorld程序去體驗下他們時候時候會執行。this

 1 public class MainActivity extends Activity {
 2     public final String TAG = "Main";
 3 
 4     @Override
 5     protected void onCreate(Bundle savedInstanceState) {
 6         super.onCreate(savedInstanceState);
 7         setContentView(R.layout.activity_main);
 8         Log.i(TAG, "onCreate被執行了.");
 9     }
10 
11     @Override
12     protected void onStart() {
13         // TODO Auto-generated method stub
14         super.onStart();
15         Log.i(TAG, "onStart被執行了.");
16     }
17 
18     @Override
19     protected void onRestart() {
20         // TODO Auto-generated method stub
21         super.onRestart();
22         Log.i(TAG, "onRestart被執行了.");
23     }
24 
25     @Override
26     protected void onPause() {
27         // TODO Auto-generated method stub
28         super.onPause();
29         Log.i(TAG, "onPause被執行了.");
30     }
31 
32     @Override
33     protected void onResume() {
34         // TODO Auto-generated method stub
35         super.onResume();
36         Log.i(TAG, "onResume被執行了.");
37     }
38 
39     @Override
40     protected void onStop() {
41         // TODO Auto-generated method stub
42         super.onStop();
43         Log.i(TAG, "onStop被執行了.");
44     }
45 
46     @Override
47     protected void onDestroy() {
48         // TODO Auto-generated method stub
49         super.onDestroy();
50         Log.i(TAG, "onDestroy被執行了.");
51     }
52 
53     @Override
54     public boolean onCreateOptionsMenu(Menu menu) {
55         // Inflate the menu; this adds items to the action bar if it is present.
56         getMenuInflater().inflate(R.menu.main, menu);
57         return true;
58     }
59 
60 }
View Code

相關文章
相關標籤/搜索