在这个应用程序,用户登录和他们的凭据检查服务器。需要显示加载屏幕,而应用程序查询服务器
用户可能会等待几秒钟,具体取决于手机可以打开数据连接的速度。我需要对话框说“请稍候”或“验证凭据”或用户点击登录后长这些行的东西。
所需的视觉顺序:按下登录 - >“请稍候”对话框显示在此相同活动 - >时,结果从服务器提供新的活动被加载(或引发错误)
当前可视顺序:按日志 - >用户等待的,如果应用程序被冻结 - >新活动被载入
我正在尝试使用AsyncTask来完成这个线程化的事情,但我现在只是没有得到它!
class Progressor extends AsyncTask<Void, Void, Void> {
ProgressDialog dialog;
protected void onPreExecute(){
dialog = ProgressDialog.show(Login.this, "Logging In",
"Verifying Credentials, Please wait...", true);
}
然后在我的onCreate方法我都喜欢的用户点击该按钮和东西的其他逻辑的,但因为我已经感动的是进入的AsyncTask方法的doInBackGround功能
/* When the Login Button is clicked: */
Button loginButton = (Button) findViewById(R.id.loginButton);
loginButton.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
Progressor showMe = new Progressor();
showMe.onPreExecute();
showMe.doInBackground(null);
showMe.onPostExecute();
和onPostExecute简单关闭对话框
为什么不工作,应该如何重新排列。我应该将哪个变量传入showMe.doInBackGround()函数,它是无效的。在调试它永远不会在这里
@Override
protected Void doInBackground(Void... arg0) {
谢谢,这个澄清真的为我做了! – CQM 2011-04-08 17:47:45