第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號(hào)安全,請(qǐng)及時(shí)綁定郵箱和手機(jī)立即綁定

Android必學(xué)-AsyncTask基礎(chǔ)

難度中級(jí)
時(shí)長49分
學(xué)習(xí)人數(shù)
綜合評(píng)分9.77
206人評(píng)價(jià) 查看評(píng)價(jià)
9.8 內(nèi)容實(shí)用
9.9 簡潔易懂
9.6 邏輯清晰
  • AsyncTask的注意事項(xiàng)

    查看全部
    0 采集 收起 來源:總結(jié)

    2020-03-27

  • asyncTask的執(zhí)行順序

    查看全部
    0 采集 收起 來源:與UI線程通信

    2020-03-27

  • 在execute執(zhí)行的參數(shù),傳遞進(jìn)來的參數(shù)作為doInBackground,String 傳遞進(jìn)來的第一個(gè)參數(shù),

    先調(diào)用PreExcute的操作,然后調(diào)用doInBackground的方法開始真正的異步操作原理,最后返回指定的類(onPostexecute)里面.

    查看全部
    0 采集 收起 來源:與UI線程通信

    2020-03-27

  • doBackground 開啟異步線程進(jìn)行操作的,基本屬于耗時(shí)的操作

    onPreExecute 線程開啟之前的操作

    前面設(shè)置的返回值設(shè)置的參數(shù)為Bitmap<String ,Void,Bitmap>,前面調(diào)用doInBackground后返回Bitmap的值,所以在onPostExcute返回的值為Bitmap,可以去設(shè)置UI。



    查看全部
    0 采集 收起 來源:與UI線程通信

    2020-03-27

  • 1.獲取傳遞進(jìn)來的參數(shù) String url=params[0]只獲取第一位參數(shù)

    2.網(wǎng)絡(luò)的操作,BitmapFactory.decodeStream 將輸入流解析成Bitmap

    3.將Bitmap作為返回值

    查看全部
  • AsynckTask 加載圖片

    查看全部
  • 他的執(zhí)行順序

    查看全部
  • onPreExcute執(zhí)行前的方法

    doInBackground? 執(zhí)行中的方法

    onPostExcute 執(zhí)行后的方法

    查看全部
  • AsynckTask的異步參數(shù),和四種方法

    查看全部
  • //Main.java:
    
    public?class?Main?extends?AppCompatActivity?{
    ????ImageView?imageView;
    ????ProgressBar?progressBar;
    ????ProgressBar?progressBar2;
    ????TextView?jishu,?hint;
    ????static?Handler?myHandler;
    ????ImageLoad?i1;
    ????Button?btn;
    
    ????@Override
    ????protected?void?onCreate(@Nullable?Bundle?savedInstanceState)?{
    ????????super.onCreate(savedInstanceState);
    ????????setContentView(R.layout.activity_main);
    ????????imageView?=?(ImageView)?findViewById(R.id.imageView);
    ????????progressBar?=?(ProgressBar)?findViewById(R.id.progressBar);
    ????????progressBar2?=?(ProgressBar)?findViewById(R.id.progressBar2);
    ????????jishu?=?(TextView)?findViewById(R.id.textView);
    ????????hint?=?(TextView)?findViewById(R.id.tv);
    ????????i1?=?new?ImageLoad(imageView,?progressBar,?progressBar2);
    ????????btn?=?(Button)?findViewById(R.id.button);
    ????}
    
    ????@Override
    ????protected?void?onPause()?{
    ????????super.onPause();
    ????????if?(i1?!=?null?&&?i1.getStatus()?==?AsyncTask.Status.RUNNING)?{
    ????????????i1.cancel(true);
    ????????}
    ????}
    
    ????public?void?startload(View?v)?{
    ????????btn.setEnabled(false);
    ????????jishu.setVisibility(View.VISIBLE);
    ????????myHandler?=?new?Handler()?{
    ????????????@Override
    ????????????public?void?handleMessage(Message?msg)?{
    ????????????????super.handleMessage(msg);
    ????????????????jishu.setText("Loading:"?+?msg.arg1?+?"%");
    ????????????????if?(msg.arg1?==?100)?{
    ????????????????????jishu.setVisibility(View.INVISIBLE);
    ????????????????????btn.setVisibility(View.INVISIBLE);
    ????????????????????hint.setVisibility(View.VISIBLE);
    ????????????????}
    ????????????}
    ????????};
    ????????i1.execute("https://ss0.bdstatic.com/70cFvHSh_Q1YnxGkpoWK1HF6hhy/it
    ????????/u=3651717973,1621948329&fm=26&gp=0.jpg");
    ????}
    
    }
    
    
    //ImageLoad.java:
    
    public?class?ImageLoad?extends?AsyncTask<String,?Integer,?Bitmap>?{
    ????ImageView?imageView;
    ????ProgressBar?progressBar;
    ????ProgressBar?progressBar2;
    ????static?Message?msg;
    
    ????public?ImageLoad(ImageView?imageView,?ProgressBar?progressBar,?ProgressBar?progressBar2)?{
    ????????this.imageView?=?imageView;
    ????????this.progressBar?=?progressBar;
    ????????this.progressBar2?=?progressBar2;
    ????}
    
    ????@Override
    ????protected?void?onPreExecute()?{
    ????????super.onPreExecute();
    ????????progressBar.setVisibility(View.VISIBLE);
    ????????progressBar2.setVisibility(View.VISIBLE);
    ????}
    
    ????@Override
    ????protected?Bitmap?doInBackground(String...?params)?{
    ????????Bitmap?bitmap?=?null;
    ????????HttpURLConnection?conn;
    ????????InputStream?is;
    ????????String?url?=?params[0];
    
    ????????try?{
    ????????????conn?=?(HttpURLConnection)?new?URL(url).openConnection();
    ????????????is?=?conn.getInputStream();
    ????????????BufferedInputStream?bis?=?new?BufferedInputStream(is);
    ????????????for?(int?i?=?0;?i?<?100;?i++)?{
    ????????????????if?(isCancelled())?{
    ????????????????????break;
    ????????????????}
    ????????????????publishProgress(i);
    ????????????????msg?=?Main.myHandler.obtainMessage();
    ????????????????msg.arg1?=?i?+?1;
    ????????????????Main.myHandler.sendMessage(msg);
    ????????????????Thread.sleep(25);
    ????????????}
    ????????????bitmap?=?BitmapFactory.decodeStream(is);
    ????????????is.close();
    ????????????bis.close();
    ????????}?catch?(IOException?e)?{
    ????????????e.printStackTrace();
    ????????}?catch?(InterruptedException?e)?{
    ????????????e.printStackTrace();
    ????????}
    ????????return?bitmap;
    ????}
    
    ????@Override
    ????protected?void?onProgressUpdate(Integer...?values)?{
    ????????super.onProgressUpdate(values);
    ????????progressBar2.setProgress(values[0]);
    ????}
    
    ????@Override
    ????protected?void?onPostExecute(Bitmap?bitmap)?{
    ????????super.onPostExecute(bitmap);
    ????????if?(isCancelled())?{
    ????????????return;
    ????????}
    ????????progressBar.setVisibility(View.INVISIBLE);
    ????????progressBar2.setVisibility(View.INVISIBLE);
    ????????imageView.setImageBitmap(bitmap);
    ????}
    }
    
    //activity_main.xml:
    
    <?xml?version="1.0"?encoding="utf-8"?>
    <LinearLayout?xmlns:android="http://schemas.android.com/apk/res/android"
    ????xmlns:app="http://schemas.android.com/apk/res-auto"
    ????xmlns:tools="http://schemas.android.com/tools"
    ????android:layout_width="match_parent"
    ????android:layout_height="match_parent"
    ????android:orientation="vertical"
    ????android:padding="10dp"
    ????tools:context=".Main">
    
    ????<Button
    ????????android:id="@+id/button"
    ????????android:layout_width="match_parent"
    ????????android:layout_height="wrap_content"
    ????????android:text="Show?the?Image"
    ????????android:layout_gravity="center"
    ????????android:onClick="startload"/>
    
    ????<TextView
    ????????android:id="@+id/tv"
    ????????android:layout_width="wrap_content"
    ????????android:layout_height="wrap_content"
    ????????android:visibility="invisible"
    ????????android:layout_gravity="center"
    ????????android:text="已成功顯示"
    ????????android:textSize="40dp"/>
    
    ????<ImageView
    ????????android:id="@+id/imageView"
    ????????android:layout_width="wrap_content"
    ????????android:layout_height="wrap_content"/>
    
    ????<ProgressBar
    ????????android:id="@+id/progressBar"
    ????????android:layout_width="match_parent"
    ????????android:layout_height="wrap_content"
    ????????android:layout_marginTop="100dp"
    ????????android:visibility="invisible"?/>
    
    ????<TextView
    ????????android:id="@+id/textView"
    ????????android:layout_width="wrap_content"
    ????????android:layout_height="wrap_content"
    ????????android:visibility="invisible"
    ????????android:textSize="20dp"
    ????????android:layout_marginTop="30dp"
    ????????android:layout_gravity="center"
    ????????android:text=""?/>
    
    ????<ProgressBar
    ????????android:id="@+id/progressBar2"
    ????????
    ????????android:layout_width="match_parent"
    ????????android:layout_height="wrap_content"
    ????????android:visibility="invisible"?/>
    
    </LinearLayout>


    查看全部
  • public?void?onPause(){
    if?(mtask?!?=?null?||?mtask.getStatus()?==?AsyncTask.Status.RUNNING)?{
    ????????mtask.cancel(true);
    ????????//若AsyncTask對(duì)象存在且處于運(yùn)行狀態(tài),便將此對(duì)象標(biāo)記為
    ????????//取消狀態(tài),然后在doInBackground()方法中利用isCancelled()
    ????????//方法進(jìn)行相應(yīng)操作
    }


    查看全部
  • ---轉(zhuǎn)
    1.protected?Bitmap?doInBackground(String...?params)傳進(jìn)來的是一個(gè)可變長的數(shù)組。<br><br>
    2.String?url?=?params[0];取出對(duì)應(yīng)的URL<br><br>
    3.URLConnection?connection:定義網(wǎng)絡(luò)連接對(duì)象<br><br>
    4.InputStream?is?:用于獲取數(shù)據(jù)的輸入流。<br><br>
    5.connection?=?new?URL(url).openConnection():獲取網(wǎng)絡(luò)連接對(duì)象。<br><br>
    6.?is?=?connection.getInputStream():獲取輸入流<br><br>
    7.bitmap?=?BitmapFactory.decodeStream();將輸入流解析成bitmap<br><br>
    8.is.close();關(guān)閉輸入流
    9.bis.close()關(guān)閉輸入流
    <br><br>
    通過這些方式就將url所對(duì)應(yīng)的圖片解析成了bitmap
    
    AsyncTask<String,Void,Bitmap>三個(gè)參數(shù)分別為:url類型,進(jìn)度值類型,返回值類型。
    這里的例子暫時(shí)不設(shè)置進(jìn)度值,url設(shè)置為String類型,又因?yàn)槲覀兗虞d的是一張Bitmap,所以返回的參數(shù)類型設(shè)置為?Bitmap。
    1.?doInBackground(String...params)傳進(jìn)來的是一個(gè)可變長數(shù)組,也就是說,我們可以傳進(jìn)不止一個(gè)參數(shù)(通過execute()傳進(jìn)來),這些參數(shù)依次存在于這個(gè)數(shù)組中?,F(xiàn)在只有一個(gè)參數(shù),所以只要寫個(gè)params[0]取出對(duì)應(yīng)的URL即可。


    查看全部
  • 回調(diào)方法的調(diào)用順序

    http://img1.sycdn.imooc.com//5e329c2a000184aa19201080.jpg

    查看全部
  • 構(gòu)建AsyncTask子類的回調(diào)方法

    http://img1.sycdn.imooc.com//5e329bc900013a8919201080.jpg

    查看全部
  • AsyncTask子類的參數(shù)

    http://img1.sycdn.imooc.com//5e329ba10001e58c19201080.jpg

    查看全部
  • 下載圖片流程
    查看全部
    0 采集 收起 來源:總結(jié)

    2020-01-26

    1. 必須在ui線程中創(chuàng)建asynctask實(shí)例,并調(diào)用execute方法

    2. 重寫的方法是系統(tǒng)自動(dòng)調(diào)用 的,也就是我們只能重寫,不能選擇何時(shí)調(diào)用

    3. 每個(gè)asynctask只能執(zhí)行一次,多次調(diào)用會(huì)引發(fā)運(yùn)行時(shí)異常

    4. 只有doinbackground才是運(yùn)行在其他線程(非主線程)更新ui是在主線程



    查看全部
    0 采集 收起 來源:總結(jié)

    2018-09-25

  • asynasynctask異步操作的示例

    繼承asynctask<string, void ,bitmap>

    string?啟動(dòng)任務(wù)時(shí)輸入的參數(shù)類型

    void后臺(tái)執(zhí)行任務(wù)時(shí)返回的? 進(jìn)度值類型

    bitmap?后臺(tái)執(zhí)行任務(wù)后返回? 結(jié)果的類型

    1. 子類調(diào)用execute方法,以URL為傳進(jìn)去的參數(shù)

    2. 調(diào)用onpreexecute,進(jìn)行初始化操作,比如將進(jìn)度條可見

    3. 調(diào)用doinbackground方法進(jìn)行真正的異步操作處理,例如耗時(shí)操作,返回一個(gè)類型給onpostexecute方法

    4. onpostexecute方法(運(yùn)行在主線程,可進(jìn)行ui操作,顯示圖片)

    查看全部
    0 采集 收起 來源:與UI線程通信

    2018-09-25

  • asynctask?<params,progress,result>?

    params:啟動(dòng)任務(wù)時(shí)輸入的參數(shù)類型

    progress:后臺(tái)執(zhí)行任務(wù)時(shí)返回的? 進(jìn)度值類型

    result :后臺(tái)執(zhí)行任務(wù)后返回? 結(jié)果的類型

    asynctask子類必須回調(diào)的方法及順序:

    2、doinbackground:必須重寫,在里面執(zhí)行了publishprogress方法,系統(tǒng)才回調(diào)3、onprogressupdate方法

    1、onpreexecute:后臺(tái)耗時(shí)任務(wù)操作前被調(diào)用,用于初始化操作

    4、onpostexecute:當(dāng)doinbackground完成后返回值,系統(tǒng)自動(dòng)調(diào)用onpostexecute,接收值

    查看全部
首頁上一頁1234567下一頁尾頁

舉報(bào)

0/150
提交
取消
課程須知
本課程是Android初級(jí)課程 1、掌握基本的Android應(yīng)用程序開發(fā)方法 2、掌握AsyncTask中個(gè)方法中參數(shù)的意義 3、掌握AsyncTask中4個(gè)常用的方法
老師告訴你能學(xué)到什么?
1、了解Android的單線程模型 2、 AsyncTask的基本構(gòu)成 3、 AsyncTask的回調(diào)方法 4、 AsyncTask實(shí)例

微信掃碼,參與3人拼團(tuán)

微信客服

購課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動(dòng)學(xué)習(xí)伙伴

公眾號(hào)

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號(hào)

友情提示:

您好,此課程屬于遷移課程,您已購買該課程,無需重復(fù)購買,感謝您對(duì)慕課網(wǎng)的支持!