AsyncTask在ViewPager中无法正常工作

时间:2017-04-14 09:37:18

标签: android android-fragments android-asynctask

我在AsyncTask的片段中遇到ViewPager课时遇到问题。

我在ViewPager的第3篇片段中添加了如下代码:

  private View.OnClickListener finishClickListener = new View.OnClickListener() {
    @Override
    public void onClick(View v) {


            UserIdAsyncTask userIdAsyncTask = new UserIdAsyncTask( getActivity(), "URL", "Test", "Value" );
            userIdAsyncTask.execute();

她是我的UserIdAsyncTask班级:

    private class UserIdAsyncTask extends AsyncTask<Void, Void, String> {

    String url = "";
    String oldpass = "";
    String newpass = "";
    private Context mContext = null;
    private ProgressDialog dialog;

    public UserIdAsyncTask( Context context, String url, String oldPass, String newPass ) {
        this.mContext = context;
        this.url = url;
        this.oldpass = oldPass;
        this.newpass = newPass;
    }

    @Override
    protected void onPreExecute() {
        dialog = ProgressDialog.show(this.mContext, "", "Please wait...");
        dialog.setCanceledOnTouchOutside(false);
        dialog.show();
    }

    @Override
    protected String doInBackground(Void... params) {
        String str = "";
        try {
            return str;
        } catch (Exception e) {
            Log.e(ThirdFrag.class.toString(), e.getMessage(), e);
        }
        return str;
    }

    @Override
    protected void onPostExecute(String response) {
        dialog.dismiss();
        Intent i = new Intent(getActivity(), ABC.class);
        startActivity(i);
        getActivity().finish();
    }
}

在给定的代码中,onPreExecute()已调用但doInBackground()从未调用过。

任何想法?我真的很挣这个。

0 个答案:

没有答案