我试图在用户单击图标后弹出一个进度对话框,以便他们知道下一个活动(标签扫描程序)正在启动。问题是只有当手机处于横向并且微调器没有旋转时才会弹出进度对话框。我注意到对话框有时会以纵向弹出,但这种情况很少见,而且通常是失焦的。我无法控制 Tag Scanner 代码(第二个 Activity),因此无法启动进度对话框。这是相关代码,有什么想法吗?我尝试从 onOptionsItemSelected 方法启动进度对话框,但我遇到了同样的问题。我也尝试从 myTask 和相同的问题中启动它。真的在这里迷路了,任何帮助将不胜感激
public boolean onOptionsItemSelected (MenuItem item){
switch (item.getItemId()){
case R.id.menu_scanner:
ProgressDialog progress = new ProgressDialog(this,R.style.MyDialog);
new MyTask(progress).execute();
break;
}
return false;
}
public class MyTask extends AsyncTask<Void, Void, Void> {
private ProgressDialog progress;
public MyTask(ProgressDialog progress) {
this.progress = progress;
}
public void onPreExecute() {
progress.setMessage("Loading Tag Scanner...");
progress.show();
progress.setCancelable(true);
}
public void onPostExecute(Void unused) {
TagContext.getInstance().initialize(APP_KEY, APP_VERSION, getApplicationContext());
TagContext.getInstance().launchViewfinder(
MainActivity.this, //Pass the parent activity for the viewfinder
listener, //Pass the listener to use for handling callbacks.
null);
progress.dismiss();
}
@Override
protected Void doInBackground(Void... arg0) {
return null;
}
}