afollestad的MaterialDialog总是崩溃我的应用程序

时间:2018-01-24 07:29:18

标签: java android

Activtiy尝试从网络上获取数据并显示MaterialDialog,当数据被完全取出时,对话框正在消失,但在某些设备应用中,此步骤崩溃,我不知道为什么以及如何解决它。

谷歌说" Dialog尝试在活动已经关闭时解散"

这是我的活动:

public class InformationActivity extends AppCompatActivity {

    public static Activity activity;
    public static MaterialDialog dialog;

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.information);
        activity = this;
        dialog = new MaterialDialog.Builder(this).build();

    }


    @Override
    protected void onResume() {
        super.onResume();

                    dialog = new MaterialDialog.Builder(this)
                            .title("Подождите")
                            .content("Загрузка")
                            .progress(true, 0)
                            .cancelable(false)
                            .show();
                    new GetUser(this, phone, new Country(this).getCountry()).execute();
        }
    }

    @Override
    protected void onPause() {
        super.onPause();
            if (dialog.isShowing()) {
                dialog.dismiss();
            }
        finish();
    }

}

这是AsyncTask

public class GetUser extends AsyncTask<String, Void, String> {

    OkHttpClient client;

    Context context;
    String url;
    String RESPONSE;
    String country;
    ArrayList<HashMap<String, String>> DATA;
    JSONArray jsonArray;
    String phone;
    public GetUser(Context context, String phone, String country)
    {
        this.context = context;
        client = new OkHttpClient();
        this.phone = phone;
        DATA = new ArrayList<>();
        this.country = country;
    }
    @Override
    protected String doInBackground(String... params) {

        try {
            RESPONSE = run(url);
        } catch (IOException e) {
            e.printStackTrace();
        }

        return "";
    }

    @Override
    protected void onPostExecute(String result) {

            if (InformationActivity.dialog.isShowing()) {
                InformationActivity.dialog.dismiss();
            }

    }

    @Override
    protected void onPreExecute() {

    }

    @Override
    protected void onProgressUpdate(Void... values) {

    }



    String run(String url) throws IOException {

        RequestBody requestBody = new MultipartBody.Builder()
                .setType(MultipartBody.FORM)
                .addFormDataPart(dataOneInf(),phone)
                .addFormDataPart(dataTwoInf(),country)
                .addFormDataPart(dataThreeInf(),eInf())
                .build();

        Request request = new Request.Builder()
                .url(dataURLInf())
                .post(requestBody)
                .build();

        Response response = client.newCall(request).execute();
        return response.body().string();
    }
}

错误

java.lang.IllegalArgumentException
View=com.android.internal.policy.PhoneWindow$DecorView{21d0893 V.E...... R......D 0,0-608,281} not attached to window manager
com.afollestad.materialdialogs.MaterialDialog.dismiss

如何解决这个问题?

0 个答案:

没有答案