如何在活动之间的长时间过渡期间安装旋转进度条(或对话框)?我已经看到了有助于实现 AsyncTask 的解决方案 - 我在帖子中提到了如何在 Android 中启动活动之前显示进度对话框的链接?,但问题是进度条没有旋转。
package expir.java.file;
import java.io.IOException;
import javax.xml.parsers.ParserConfigurationException;
import org.xml.sax.SAXException;
import android.app.Activity;
import android.app.ProgressDialog;
import android.content.Intent;
import android.os.AsyncTask;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.Window;
import android.widget.Button;
public class ExpirActivity extends Activity {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_NO_TITLE);
setContentView(R.layout.main);
Button mapButton = (Button)findViewById(R.id.first_button);
mapActivityIntent = new Intent(this, MyMapActivity.class);
pDialog = new ProgressDialog(this);
mapButton.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
pDialog.setMessage("Loading...");
new MyTask(pDialog).execute();
}
});
Button downloadButton = (Button)findViewById(R.id.second_button);
downloadButton.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
as.DownloadFromUrl("0", "null");;
}
});
Button parseButton = (Button)findViewById(R.id.third_button);
parseButton.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
SAXParserCreateDataBase gi = new SAXParserCreateDataBase();
try {
gi.start(ExpirActivity.this);
} catch (SAXException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (ParserConfigurationException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
});
Button updateButton = (Button)findViewById(R.id.fourth_button);
updateButton.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
SAXParserCreateDataBase gi = new SAXParserCreateDataBase();
try {
gi.update(ExpirActivity.this);
} catch (ParserConfigurationException e) {
e.printStackTrace();
} catch (SAXException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}
});
}
public class MyTask extends AsyncTask<Void, Void, Void> {
public MyTask(ProgressDialog progress) {
this.progress = progress;
}
public void onPreExecute() {
progress.show();
}
public Void doInBackground(Void... unused) {
startActivity(mapActivityIntent);
return null;
}
public void onPostExecute(Void unused) {
progress.dismiss();
}
ProgressDialog progress;
}
DownloadPrimaryDate as = new DownloadPrimaryDate();
Intent mapActivityIntent;
ProgressDialog pDialog;
}
更新:
LogCat 结果:
FirstActivity.onCreate()
FirstActivity.onStart()
FirstActivity.onResume()
FirstActivity.onPause()
SecondActivity.onCreate()
SecondActivity.onStart()
SecondActivity.onResume()
FirstActivity.onStop()
这就解释了为什么会这样。
更新
在我意识到我在想什么 - 并不是我所有在活动之间实现这种转换的尝试都是均匀的。