2014年11月10日android學習總結

來源:互聯網
上載者:User

標籤:android

一、線程


1、UI線程

a、Handler handler = new Handler();

      Runnable runnable = new Runnable(){

      public void run(){

      }

      };

   handler.post(runnable);


b、Handler handler = new Handler(){

      public void handlermessage(Message msg){

      }

      };

      handler.sendmessage();

  


二、新線程

a、Thread thread = new Thread(Runnable(){

    public void run(){

           }

    ).start();

      

b、HandlerThread handlerthread = new HandlerThread("handler_Thread");

      handlerthread.start();

      MHandler  mhandler = new Handler(handlerthread.getLooper()) ;

      Message msg =  hangdler.obtainMessage();

      msg.sendToTarget;

  

      class MHandler extends Handler{

      handleMessage

      }  


c、AsyncTask

步驟:

①執行個體化AsyncTask:

執行個體化AsyncTask然後通過task.exec(pamas);傳進去參數,這個參數列表是動態,可以是一個也可以使多個,長度可變。

  AsyncTask,第一個參數會傳進去這個方法doInBackground(params),第二個參數是資料更新的值,第三個是處理事務返回的結果。

②onPreExecute方法:

這個方法沒有參數,也沒有傳回值,可以在這個方法裡,做一些提醒。比如show一個Dialog,或者彈個Toast告訴使用者開始下載啦。

③doInBackground(params)方法:

進入AsyncTask內部結構,首先將執行reslut doInBackground(params)方法,這個方法將處理耗時事務,exec()的參數將會傳進這個方法做參數,而傳回值將會作為onPostExecute()的參數。如果要更新進度的話,需執行publicProgress()方法。

④onProgressUpdate(values)方法:

這個方法的參數必須在doInBackground()方法裡執行publicProgress()方法,這個方法將會把參數傳遞進onProgressUpdate()方法裡,然後可以在這個方法做一些ui上的更新展示,比如進度條的值就可以通過這個values值動態改變。

⑤onPostExecute(result)方法:

這裡就是交易處理完畢的走的方法,doInBackground方法執行的結果將傳到這裡,如果這個方法返回了資料。在這個方法裡可以處理Ui,可以把處理完的資料展示在ui上。比片啊,文字啊,一切你想要的結果。

  



2014年11月10日android學習總結

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.