Android AsyncTask等待其他功能完成

问题描述

我尝试在android中异步执行两个函数。所以我需要第一个功能放弃第二个功能。我尝试使用AsyncTask来执行此操作。但是问题是第一个函数不能等到第一个函数完成。

    private class DemandeConge extends AsyncTask<Void,Void,Void> {
    protected void onPreExecute() {
        super.onPreExecute();
        Log.i("we are here","**************On pre Exceute......***************");
        p=new ProgressDialog(getActivity());
        p.setMessage("Please wait...It is downloading");
        p.setIndeterminate(false);
        p.setCancelable(false);
        p.show();
        Log.i("we are here","**************On pre Exceute......***************");
    }

    @Override
    protected Void doInBackground(Void... params) {
        Log.i("we are here","**************oOn doInBackground...***************");
        getSoldeConge();
        Log.i("we are here","**************On doInBackground...***************");
        return null;
    }

    @Override
    protected void onProgressUpdate(Void... values) {
        super.onProgressUpdate(values);
        Log.i("we are here","**************onProgressUpdate...***************");
        Log.i("we are here","**************onProgressUpdate...***************");
    }

    /**
     * `onPostExecute` is run after `doInBackground`,and it's
     * run on the main/ui thread,so you it's safe to update ui
     * components from it. (this is the correct way to update ui
     * components.)
     */
    @Override
    protected void onPostExecute(Void param) {

        Log.i("we are here","**************onPostExecute...***************");
        Log.i("we are here","**************onPostExecute...***************");

        Log.i("we are here","add conge()");
        p.dismiss();

    }

    @Override
    protected void onCancelled() {
        super.onCancelled();
        p.dismiss();
        Log.i("we are here","**************onCancelled...***************");

    }
}

我有两个函数,第一个是getSoldeConge();,它通过翻新来获取一些数据,第二个函数将在第二个Log.i("we are here","add conge()");有鳍时被排除,但是在我的情况下,第二个函数将在第一个函数完成之前运行

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)