安卓:AsyncTask的ProgressDialog不会的ActivityGroup开 [英] Android: AsyncTask ProgressDialog will not open in ActivityGroup
问题描述
我想有AA进度对话框打开的时候轮询我的服务器。这个类是的ActivityGroup,因为它是嵌套在标签栏之内。为了保持在框架内的视图,所述的ActivityGroup是必要的。这里是我的ActivityGroup类的声明:
I am trying to have a a progress dialog open when polling my server. The class is an ActivityGroup because it is nested within a tab bar. To keep the view within the frame, the ActivityGroup is needed. Here is the declaration of my ActivityGroup class:
public class CheckInActivity extends ActivityGroup{
...
public void onCreate(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
setContentView(R.layout.checkin);
new LocationControl().execute(this);
现在我的AsyncTask类是相同的CheckInActivityClass这样中:
Now my AsyncTask class is within the same CheckInActivityClass as such:
private class LocationControl extends AsyncTask<Context, Void, Void>
{
private final ProgressDialog dialog = new ProgressDialog(CheckInActivity.this);
protected void onPreExecute()
{
this.dialog.setMessage("Determining your location...");
this.dialog.show();
}
当我运行给定的应用程序,它得来与窗口管理$ BadTokenException错误。陈述它不能启动与未知令牌的窗口。我试图做一个示例应用程序,这只是一个普通的活动(没有的ActivityGroup)和它的工作就好了。
When I run the given app it throughs an error relating to WindowManager$BadTokenException. Stating the it cannot start the window with an unknown token. I tried making a sample app that is just a regular Activity(not ActivityGroup) and it worked just fine.
有谁知道如何修改此,使其工作,还是周围的工作,将允许嵌套的进度条到标签栏之内?任何帮助是极大的AP preciated。
Does anyone know how to modify this to make it work, or a work around that will allow the progress bar to be nested within the tab bar? Any help is greatly appreciated.
推荐答案
如果在的ActivityGroup是你嵌套活动两个以上的水平TabActivity内。 Android不此刻的支持,但是有解决方法。你必须父活动传递给对话框。
If the ActivityGroup is within a TabActivity you have nested activities with more then two levels. Android doesn't support this at the moment but there is a workaround. You have to pass the parent activity to the dialog.
为此,在活动课中创建一个helper方法:
Create a helper method for this purpose in the activity class:
private Context getDialogContext() {
Context context;
if (getParent() != null) context = getParent();
else context = this;
return context;
}
然后换行
private final ProgressDialog dialog = new ProgressDialog(CheckInActivity.this);
到
private final ProgressDialog dialog = new ProgressDialog(getDialogContext());
这篇关于安卓:AsyncTask的ProgressDialog不会的ActivityGroup开的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!