如何显示进度条几秒钟然后转移到android中的活动?

时间:2016-03-30 05:53:05

标签: android

我有一项活动,在服务器响应成功时我想显示几秒/分钟的进度条,几分钟后关闭进度条然后更改活动。我该怎么做。

这是我的代码

public void conditions() throws JSONException {
        if (m_oResponseobject.getString("resultdescription").equalsIgnoreCase("Transaction Successful")) {
            new Handler().postDelayed(new Runnable() {
                @Override
                public void run() {
                    CProgressBar.getInstance().showProgressBar(getApplicationContext(), "Please wait while rediecting to website");

                }
            }, 3000);
            CProgressBar.getInstance().hideProgressBar();
            Intent i = new Intent(CDealAppListingDetails.this, CMainActivity.class);
            startActivity(i);

        }
    }

2 个答案:

答案 0 :(得分:1)

int DELAY = 3000;
CProgressBar.getInstance().showProgressBar(getApplicationContext(), "Please wait while rediecting to website");

Handler handler = new Handler();
handler.postDelayed(new Runnable() {            
    @Override
    public void run() {
 CProgressBar.getInstance().hideProgressBar();
        Intent i = new Intent(CDealAppListingDetails.this, CMainActivity.class);
        startActivity(i);                
    }
}, DELAY);

答案 1 :(得分:0)

试试这个:

     CProgressBar.getInstance().showProgressBar(getApplicationContext(), "Please wait while rediecting to website");
     new Handler().postDelayed(new Runnable() {
                    @Override
                    public void run() {
                        CProgressBar.getInstance().hideProgressBar();
                        Intent i = new Intent(CDealAppListingDetails.this, CMainActivity.class);
                        startActivity(i);
                    }
                }, 3000);