Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/206.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android AsyncTask调用onProgressUpdate或onPostExecute延迟_Android_Android Asynctask - Fatal编程技术网

Android AsyncTask调用onProgressUpdate或onPostExecute延迟

Android AsyncTask调用onProgressUpdate或onPostExecute延迟,android,android-asynctask,Android,Android Asynctask,这表明: 我有个问题 为什么bg0、bg1、b2已被记录,但onProgressUpdate和onPostExecute需要服务回调才能运行 09-22 13:13:09服务开始 但仍然是09-22 13:13:24.824广播回调,然后是onProgressUpdate和onPostExecute开始运行 我想知道,为什么会这样 我试图搜索,但我不知道如何写一个好的关键字。所以我没有找到一个WSER 真诚的。谢谢。在AsycTask 调用这些函数有一个顺序 当doInBackground(Pa

这表明:

我有个问题

为什么bg0、bg1、b2已被记录,但onProgressUpdate和onPostExecute需要服务回调才能运行

09-22 13:13:09服务开始

但仍然是09-22 13:13:24.824广播回调,然后是onProgressUpdate和onPostExecute开始运行

我想知道,为什么会这样

我试图搜索,但我不知道如何写一个好的关键字。所以我没有找到一个WSER

真诚的。谢谢。

在AsycTask

调用这些函数有一个顺序

doInBackground(Params…完成某个单元任务时,它将推送到publishProgress(Progress…,并调用onProgressUpdate(Progress…)更新UI

1onPreExecute(),在执行任务之前在UI线程上调用。 此步骤通常用于设置任务,例如在用户界面中显示进度条

2.doInBackground(Params…,在onPreExecute()完成执行后立即在后台线程上调用。 此步骤用于执行可能需要很长时间的背景计算。 异步任务的参数被传递到此步骤

此步骤必须返回计算结果,并将返回到最后一步

此步骤还可以使用发布进度(进度…发布一个或多个进度单元。 这些值在UI线程的onProgressUpdate(Progress…)步骤中发布

3.)onProgressUpdate(Progress…,在调用publishProgress(Progress…)后在UI线程上调用

执行的时间未定义。此方法用于在后台计算仍在执行时在用户界面中显示任何形式的进度。例如,它可以用于制作进度条动画或在文本字段中显示日志


4.onPostExecute(Result),后台计算完成后在UI线程上调用。后台计算的结果作为参数传递到此步骤。

因此您想知道,为什么onProgressUpdatepublishProgress之后运行?。这是合乎逻辑的。当您调用publishProgress(progress…时,这意味着您已将信息发送到您的onProgressUpdate(progress…。(将在onProgressUpdate中的UI线程上发布的值),它将更新UI中的相关控件(进度条等)

哦,对不起。我的问题是:为什么“onProgressUpdate”函数在“publishProgress(0);”之后运行?执行15秒。@abcdlzy此步骤必须返回doInBackground(Params…)中的计算结果,并将返回到最后一步。此步骤还可以使用publishProgress(进度…)发布一个或多个进度单元。这些值发布在用户界面线程的onProgressUpdate(Progress…)步骤中。@abcdlzy要进行用户界面更改,您应该按照您的建议在onpostexecutethanks中进行。我正在与我的小组成员交谈,项目代码是否有问题。我在中国的大学,GMT+8,将在23:00,我的大学将断开互联网。晚安。^ ^,明天见。我的ProgressUpdate和onCancelled代码丢失
@Override
,请尝试添加它,然后我的应用程序工作起来看起来很好。这就是我的代码问题。因此,解决方案是不要缺少
@覆盖
。谢谢你回答我的问题。^ ^是的,publishProgress将信息发送到onProgressUpdate,我知道这将更新UI,但我有问题,问题是UI看起来不工作。我尝试调试。因此我在代码中添加了一些日志。当我添加日志代码时,我发现了问题。你能给我一些建议吗?@abcdlzy要做Ui更改你应该在OnPostExecute中做。你的Ui有什么问题?你的问题到底是什么?我在进度条上用过这个东西。当然我可以给出建议,如果知道你的问题是什么?你的UI没有及时更新吗?@Zeeshan我的问题来自:当UI单击登录按钮时。该按钮调用[doLogin.execute(“”;])。然后执行SendBroadCast\u登录(参数…),我只需要执行SendBroadCast\u登录(参数…)。此时,我希望UI可以运行。但是…我单击按钮,我发现UI看起来不工作,我尝试查找,为什么UI看起来不工作。所以我尝试添加日志,当我获得日志信息时,我发现这次在ProgressUpdate和onPostExecute上UI不工作也不执行。很抱歉我的英语不好。
    class DoLogin extends AsyncTask<String, Integer, String> {// 继承AsyncTask
    @Override
    protected String doInBackground(String... params) {// 处理后台执行的任务,在后台线程执行
        ServerAnalyze.log("消息", "登陆", "手动登陆函数开始启动.");

        EditText etStuId = (EditText) findViewById(R.id.tbStudentID);
        EditText etPwd = (EditText) findViewById(R.id.tbPassword);

        global.setStudentID(etStuId.getText().toString());
        String Password = etPwd.getText().toString();
        global.setImei(((TelephonyManager) getSystemService(TELEPHONY_SERVICE))
                .getDeviceId());
        Log.i("loginclick", "bg0");
        global.giitServiceInterface.SendBroadCast_Login(global.getStudentID(), Password, global.getImei());
        Log.i("loginclick", "bg1");
        publishProgress(0);
        Log.i("loginclick", "bg2");
        return "";
    }

    protected void onProgressUpdate(Integer... progress) {// 在调用publishProgress之后被调用,在ui线程执行
        Log.i("loginclick", "update");
    }

    @Override
    protected void onPostExecute(String result) {// 后台任务执行完之后被调用,在ui线程执行
        // progressDialog.dismiss();
        Log.i("loginclick", "finish");
    }

    @Override
    protected void onPreExecute() {// 在doInBackground(Params...)之前被调用,在ui线程执行

        Button btnloginButton = (Button) findViewById(R.id.btnlogin);
        btnloginButton.setText("正在登陆中,请稍候...");
        btnloginButton.setBackgroundColor(getResources().getColor(
                R.color.huise));
    }

    protected void onCancelled() {// 在ui线程执行

    }

}
09-22 13:13:09.753: I/loginclick(1751): bg0
09-22 13:13:09.763: I/loginclick(1751): bg1
09-22 13:13:09.763: I/loginclick(1751): bg2
09-22 13:13:09.773: I/Giit Service(1751): Start
09-22 13:13:24.824: I/loginclick(1751): update
09-22 13:13:24.824: I/loginclick(1751): finish
09-22 13:13:24.834: I/[GiitParamClass-Action](1751): 1
09-22 13:13:24.844: I/[GiitParamClass-BooleanResult](1751): false
09-22 13:13:24.844: I/[GiitParamClass-intResult](1751): 0