我尝试打开第二个活动,需要一些时间从主要活动开始从互联网加载数据,在此期间,我的屏幕将以黑色显示,所以我决定使用进度对话框显示“嘿,我是还活着,请不要关闭我!“ 一切都很顺利但唯一的问题是旋转器没有旋转。这是我的代码: 单击按钮后: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();
}
}
我试图删除“startActivity(new Intent(”com.android.ricky.RESULT_DETAIL“));”和“myDialog.dismiss();”同时,旋转器旋转&gt;&lt; 请帮助,非常感谢!
答案 0 :(得分:4)
你的概念有点混乱和错误,
您必须在按钮的单击时启动第二个活动,然后第二个活动的onCreate()
执行YourAsyncTask()
。并在doInBackground()
AsyncTask
的{{1}}下载第二个活动的互联网数据。完成下载后,在onPostExecute()
AsyncTask
,然后dismiss()
ProgressDialog
准备第二个活动的用户界面。