0

在我的应用程序中,我有一个帐户激活表单,它通过 Internet 进行身份验证。同时(在单击激活按钮之后)我希望向用户显示某种 UI,以便他知道激活正在进行中。请你可以和我分享代码。另外,应用程序激活后如何创建成功的文件。谢谢

4

3 回答 3

2

您可以像这样使用异步任务

在 OnCreate 之前声明一个进度对话框

ProgressDialog 对话框;

并添加一个用 AsyncTask 扩展的类,例如

private class LongOperation extends AsyncTask<String, Void, String> {

        @Override
        protected String doInBackground(String... params) {

            // perform the action which you want to do

            return null;
        }

        /*
         * (non-Javadoc)
         * 
         * @see android.os.AsyncTask#onPostExecute(java.lang.Object)
         */
        @Override
        protected void onPostExecute(String result)
 {
            // execution of result of Long time consuming operation

  // perform task which you want to display once background task is finished 

            dialog.dismiss();


        }

        /*
         * (non-Javadoc)
         * 
         * @see android.os.AsyncTask#onPreExecute()
         */
        @Override
        protected void onPreExecute() {

// initialize dialog 

            dialog = new ProgressDialog(Comment.this);

// set message 
            dialog.setMessage("Please wait while processing");
            dialog.setIndeterminate(true);
            dialog.setCancelable(false);
            dialog.show();

        }

        /*
         * (non-Javadoc)
         * 
         * @see android.os.AsyncTask#onProgressUpdate(Progress[])
         */
        @Override
        protected void onProgressUpdate(Void... values)

        {

        }

    }

也可以参考这个链接,

http://www.vogella.com/articles/AndroidPerformance/article.html#asynctask

于 2012-07-27T06:30:16.107 回答
1

看看: http: //developer.android.com/reference/android/os/AsyncTask.html 您可以在后台执行线程时提供自己的加载布局。非常容易使用。

于 2012-07-27T06:08:37.433 回答
0

当您AsyncTask用来完成此操作时,我假设您已阅读文档。如果没有,我可以为您提供一个示例:

public void doInBackground(Void... arg0) {

  int i;

  for(i = 0; i < 10; i++) {
   publishProgress(i);
  }
}

doInBackground方法发布进度到onProgressUpdate方法

   public void onProgressUpdate(int arg0) {
       Log.d(arg0);
    }
于 2012-07-27T07:21:22.843 回答