亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

進度診斷未更新

進度診斷未更新

烙印99 2022-08-17 15:28:25
我一直在使用AsyncTask下載某個文件,并經歷了一些教程,只是未能使進度條隨著下載而移動。代碼是和 AsyncTask 調用一個方法來執行 HTTP 連接,然后返回以正確的方式對數據進行排序,以便為應用程序操作它這是我的AsynTask,在主要活動    private class getFood extends AsyncTask<Void, Integer, Cursor> {    private ProgressDialog mProgressDialog;    @Override    protected Cursor doInBackground(Void... params) {        // Create URL object        String site = "https://afternoon-ridge-50060.herokuapp.com/allsnacks";        URL url = createUrl(site);        // Perform HTTP request to the URL and receive a JSON response back        String jsonResponse = null;        try {            String jsonResponseEmpty = "";            // If the URL is null, then return early.            if (url == null) {                jsonResponse = jsonResponseEmpty;            }            HttpURLConnection urlConnection = null;            InputStream inputStream = null;            try {                assert url != null;                urlConnection = (HttpURLConnection) url.openConnection();                urlConnection.setReadTimeout(20000 /* milliseconds */);                urlConnection.setConnectTimeout(25000 /* milliseconds */);                urlConnection.setRequestMethod("GET");                urlConnection.setRequestProperty("Authorization", "\"token\": " + token);                urlConnection.connect();
查看完整描述

2 回答

?
達令說

TA貢獻1821條經驗 獲得超6個贊

根據安卓文檔:

“onProgressUpdate(Progress...),在調用 publishProgress(Progress...) 后在 UI 線程上調用。執行時間未定義。此方法用于在后臺計算仍在執行時在用戶界面中顯示任何形式的進度。例如,它可用于對進度條進行動畫處理或在文本字段中顯示日志”

使用它


查看完整回答
反對 回復 2022-08-17
?
暮色呼如

TA貢獻1853條經驗 獲得超9個贊

您必須發布進度,然后只有 具有適當的值。Integer... values


像這樣:


@Override

protected String doInBackground(Context... params) {

    //Part-1 of the task done

    publishProgress(20);


    //Part-2 of the task done

    publishProgress(50);


    //Part-3 of the task done

    publishProgress(100);


    return “success”;

}


查看完整回答
反對 回復 2022-08-17
  • 2 回答
  • 0 關注
  • 140 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號