When I start an activity by intent that takes some time before showing up (in my case the zxing intent, see http://code.google.com/p/zxing) I want to 开发者_开发百科show some progress indicator to the user until the activity is created and can get started.
Is there any way to do this?
In your onCreate
method you should call showDialog
first right at the beginning and then define the dialog in the onCreateDialog
method (as that method will get called when you call showDialog). Once your activity has created everything you can just call dismissDialog
Something like this:
public class Test extends Activity {
static final int LOADING_DIALOG = 1;
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
showDialog(LOADING_DIALOG);
...
...
dismissDialog(LOADING_DIALOG);
}
protected Dialog onCreateDialog(int id) {
switch(id)
{
case LOADING_DIALOG:
ProgressDialog loadingDialog = new ProgressDialog(this);
loadingDialog.setMessage("Waiting to load images...");
loadingDialog.setCancelable(false);
return loadingDialog;
}
}
}
精彩评论