標籤:
一、重寫父類finish();函數。
@Override public void finish() { //其他結束之前的操作,這裡寫的手機"back"鍵都有效 //使用關鍵字super調用父類的finish()函數 super.finish(); //結束動畫 overridePendingTransition(R.anim.push_left_0, R.anim.push_left_1); }
這樣寫的好處如果使用了finish()函數,手機"back"鍵都有效。如果要儲存一些重要的值,或者判斷都可以複寫這個finish()函數。
finish函數僅僅把當前Activity退出了,但是並沒有釋放他的資源。安卓系統自己決定何時從記憶體中釋放應用程式。當系統沒有可用記憶體到時候,會按照優先順序,釋放部分應用。
二、Activity.onDestory()
系統銷毀了這個Activity的執行個體在記憶體中佔據的空間。
在Activity的生命週期中,onDestory()方法是他生命的最後一步,資源空間等就被回收了。當重新進入此Activity的時候,必須重新建立,執行onCreate()方法。
三、System.exit(0)
這個是退出整個應用程式的,是針對整個Application的。將整個程式進程直接關閉退出。
四、onCheckedChanged(RadioGroup arg0, int checkId);
@Override // RadioGroup監聽 public void onCheckedChanged(RadioGroup arg0, int checkId) { arg0.check(checkId); }
這是一個RadioGroup控制項監聽實現的介面。但是如果有需要使用這個函數,也可以靈活應用。
1、調用onCheckedChanged(RadioGroup arg0, int checkId);
函數時,需要尋找RadioGroup的id,以及尋找RadioButton的id。這些值賦值進去。
樣本:
RadioGroup radioGroup = (RadioGroup) findViewById(R.id.radioGroup);RadioButton radio = (RadioButton) findViewById(R.id.radio);onCheckedChanged(radioGroup, radio);
2、arg0.check(checkId);
這個作用就是自動幫你選擇RadioButton。只要把RadioGroup、RadioButton的id傳進去,實現什麼都可以了。
五、附帶常用textview尋找id繫結控制項並顯示text快捷方法
public void setTextViewIdAndShowText(int nRid, String showText){ try { TextView txtTextView = (TextView) findViewById(Rid); if (txtTextView != null) txtTextView.setText(txt == null ? "" : txt); } catch (ClassCastException fe) { }}
Android 關於finish()、onDestory()、System.exit(0)、onCheckedChanged(RadioGroup arg0, int checkId)總結