android 在每個狀態的切換都有不同的事件,從 MainActivity 腳本中執行監聽事件
package com.abf1.mac.term1_counter; import android.support.v7.app.ActionBarActivity; import android.os.Bundle; import android.view.Menu; import android.view.MenuItem; import android.view.View; import android.widget.TextView; public class MainActivity extends ActionBarActivity { public int i = 0; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); } public void ADD_click(View view){ TextView output = (TextView)findViewById(R.id.lblShow); i++; output.setText(Integer.toString(i)); } public void LESS_click(View view){ TextView output = (TextView)findViewById(R.id.lblShow); i--; output.setText(Integer.toString(i)); } @Override protected void onResume(){ super.onResume(); TextView output = (TextView)findViewById(R.id.lblShow); output.setText("RESUME!"); } @Override protected void onStart(){ super.onStart(); System.out.println("ON START!"); } @Override protected void onStop(){ super.onStop(); System.out.println("Application Stopped!"); } @Override protected void onPause(){ super.onPause(); System.out.println("Application Pause!"); } @Override protected void onRestart(){ super.onRestart(); System.out.println("Application Restart!"); } @Override protected void onDestroy(){ super.onDestroy(); System.out.println("Application Destroy!"); } }你可以看到要是應用程式到背景,再回到視窗,會把 lblShow 的值改成 "RESUME!"
繼續執行作業回到原本的流程中
沒有留言:
張貼留言