如何在Android中显示进度条几秒钟,然后转到活动界面?

3
我有一个活动,在服务器响应成功后,我想显示进度条几秒钟/几分钟,然后在几分钟后解除进度条并更改活动。我该怎么做?
以下是我的代码:
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);

        }
    }

你的代码有什么问题? - Vivek Mishra
快速移除进度条 - Nitin
我想要显示进度条几秒钟,然后取消进度条,接着显示活动。 - Nitin
2个回答

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);

显示错误:android.view.WindowManager$BadTokenException:无法添加窗口--令牌null不是应用程序的。 - Nitin

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);

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接