Android 关闭progressdialog并触发另一个progressdialog

Android 关闭progressdialog并触发另一个progressdialog,android,android-alertdialog,progressdialog,timertask,Android,Android Alertdialog,Progressdialog,Timertask,我的目标是在没有互联网连接的情况下关闭初始progressdialog(比如10秒后),然后触发另一个alertdialog,提示用户检查互联网连接并重试 以下是我的RemoteDataTask类: private class RemoteDataTask extends AsyncTask<Void, Void, Void> { @Override protected void onPreExecute() { super.onPreExec

我的目标是在没有互联网连接的情况下关闭初始progressdialog(比如10秒后),然后触发另一个alertdialog,提示用户检查互联网连接并重试

以下是我的RemoteDataTask类:

    private class RemoteDataTask extends AsyncTask<Void, Void, Void> {
    @Override
    protected void onPreExecute() {
        super.onPreExecute();
        /*
        Create the progressdialog
         */
        mProgressDialog = new ProgressDialog(MainActivity.this);
        //title :
        mProgressDialog.setTitle("SmartShop. Shopping made easy !");
        //message :
        mProgressDialog.setMessage("Chargement...");
        mProgressDialog.setIndeterminate(false);
        //show the progressdialog...Only if gpslocation is available !! :)
        if (gps.canGetlocation()){
            mProgressDialog.show();
            }
        //mProgressDialog.show();
    }

    @Override
    protected Void doInBackground(Void... params) {

        long delayInMillis = 3000;
        list_of_articles = new ArrayList<Articles>();
        try {
            timer.schedule(new TimerTask() {
            @Override
            public void run() {
                mProgressDialog.dismiss();
            }
        },delayInMillis );
            // Locate the class table named "Article" in Parse.com
            ParseQuery<ParseObject> query = new ParseQuery<ParseObject>(
                    "Article");
            // Locate the column named "ranknum" in Parse.com and order list
            // by ascending
            //query.orderByAscending("ranknum");
            query.whereWithinKilometers("Localisation_Vendeur",device_location,rayon);
            ob = query.find();
            for (ParseObject article : ob) {
                // Locate images in article_image column
                ParseFile image = (ParseFile) article.get("Image_Article");

                Articles map = new Articles();
                map.setArticle_name((String) article.get("Nom_Article"));
                map.setArticle_vendor((String) article.get("Nom_Vendeur"));
                //map.setArticle_vendor((String) article.get("reduction"));
                map.setArticle_image(image.getUrl());
                list_of_articles.add(map);
            }
        } catch (ParseException e) {
            Log.e("Error", e.getMessage());
            e.printStackTrace();
        }
        return null;
    }

    @Override
    protected void onPostExecute(Void result) {

        // Locate the listview in listview_main.xml
        listview = (ListView) findViewById(R.id.listview);
        // Pass the results into ListViewAdapter.java
        adapter = new ListViewAdapter(MainActivity.this,
                list_of_articles);
        // Binds the Adapter to the ListView
        listview.setAdapter(adapter);
        // Close the progressdialog
        mProgressDialog.dismiss();
    }



}
我的progressdialog不会使用此代码关闭。怎么了?我应该在哪里调用第二个alertdialog检查internet连接并重试


谢谢

您应该仅从UI线程执行UI修改。计时器在自己的线程中运行其任务,而不是在UI线程中。您可以这样做:

runOnUiThread(new Runnable() { public void run() {
    mProgressDialog.dismiss();
}});

并以同样的方式启动一个新对话框。

谢谢您的回复,但我不明白您应该仅从UI线程执行UI修改。你能给我指一份教程/文档吗?顺便说一句,我把计时器移到了onPreExecute函数,现在prgressdialog确实关闭了。@RidouaneHicham