Android 關於finish()、onDestory()、System.exit(0)、onCheckedChanged(RadioGroup arg0, int checkId)總結

來源:互聯網
上載者:User

標籤:

一、重寫父類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)總結

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.