【发布时间】:2014-05-31 10:00:40
【问题描述】:
亲爱的各位,
我目前正在开发一个需要显示进度对话框的 android 应用程序。为此,我需要一个上下文对象。
我在扩展应用程序的类中执行此任务。但是每次我尝试访问上下文对象时,它都会向我显示此行的WindowManager.BadTokenException
Dialog dialog=ProgressDialog.show(getApplicationContext(), "Status", "Downloading The master");
请帮助我哪里做错了
编辑: 下面是我的代码!
public class FlightStatus extends Application {
private Context context;
@Override
public void onCreate() {
// TODO Auto-generated method stub
super.onCreate();
SharedPreferences preference=getSharedPreferences("FlightStatus", 1);
if(preference.getBoolean("firstLaunch", true))
{
try {
Dialog dialog=ProgressDialog.show(getApplicationContext(), "Status!", "Downloading The master!!");
XLSReadHelper excelReader=new XLSReadHelper(getApplicationContext());
//excelReader.readExcelFile(Environment.getExternalStorageDirectory()+"/UHCPAudit/cases.xls");
excelReader.readExcelFile();
Log.d("Excel Operation ", "records read!!");
preference.edit().putBoolean("firstLaunch", false).commit();
dialog.dismiss();
} catch (Exception e) {
// TODO: handle exception
Log.d("Excel Operation ", e.getMessage());
}
}
}
}
【问题讨论】:
标签: android android-layout android-fragments android-view android-context