简体   繁体   English

为什么我的进度对话框在新意图start()时没有旋转?

[英]Why my progress dialog is not spinning while new intent start()?

I try to open the 2nd activity which require some time to load data from internet first from main activity, during this period, my screen will full in black, so i decide to use progress dialog to show "hey, I'M STILL alive, DON'T CLOSE ME!" 我尝试打开第二个活动,需要一些时间从主要活动加载来自互联网的数据,在此期间,我的屏幕将全黑,所以我决定使用进度对话框显示“嘿,我仍然活着,别关我!“ Everything went perfectly but the only problem is that the spinner is not rotating. 一切都很顺利但唯一的问题是旋转器没有旋转。 here is my code: after button is click: new YourAsyncTask().execute(); 这是我的代码:单击按钮后:new YourAsyncTask()。execute();

public class YourAsyncTask extends AsyncTask<Void, Void, Void> {

    private ProgressDialog myDialog;

    @Override
    protected void onPreExecute() {
        //show your dialog here
        myDialog = ProgressDialog.show(ScrollingTab.this, "loading..", "please wait..", true, true);  
        myDialog.setProgressStyle(ProgressDialog.STYLE_SPINNER); 
    }

    @Override
    protected Void doInBackground(Void... params) {        
        //update your DB - it will run in a different thread

        startActivity(new Intent("com.android.ricky.RESULT_DETAIL"));
        return null;
    }

    @Override
    protected void onPostExecute(Void result) {
        //hide your dialog here
        myDialog.dismiss();
    }
}

I have tried to remove " startActivity(new Intent("com.android.ricky.RESULT_DETAIL"));" 我试图删除“startActivity(new Intent(”com.android.ricky.RESULT_DETAIL“));” and "myDialog.dismiss();" 和“myDialog.dismiss();” at the same time, then the spinner is rotating >< please help, thanks a lot! 同时,旋转器旋转> <请帮忙,非常感谢!

Your concept is little bit confusing and wrong, 你的概念有点混乱和错误,

You have to start 2nd Activity on button's click and then onCreate() of your 2nd Activity execute the YourAsyncTask() . 您必须在按钮单击时启动第二个活动,然后第二个活动的onCreate()执行YourAsyncTask() And download data from internet for 2nd Activity in doInBackground() of AsyncTask . 并在AsyncTask doInBackground()中从Internet下载第二个Activity的数据。 After complete the download prepare your UI for 2nd Activity in onPostExecute() of AsyncTask and then dismiss() the ProgressDialog . 完成下载后,在AsyncTask onPostExecute()中准备第二个活动的UI,然后dismiss() ProgressDialog

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM