如何设置进度条直到从服务器使用json获取数据?

Yug*_*esh -1 android android-asynctask

可能重复:
Android AsyncTask进度条

我正在使用登录过程,在服务器上获取数据的时间是延迟.所以我想设置一个进度条为tat delay.how设置进度条直到得到服务器的响应.有人知道答案请帮助我.

Ram*_*ran 5

private class LongOperation extends AsyncTask<String, Void, String> 
{
    protected void onPreExecute() 
    { 
        progressDialog = new ProgressDialog(activity.this); 
        progressDialog.setTitle("Processing...");
        progressDialog.setMessage("Please wait...");
        progressDialog.setCancelable(true);
        progressDialog.show();
    }

    protected String doInBackground(String... params) 
    {
        try 
        {
            //Getting data from server
        }
        catch (Exception e) {
            e.printStackTrace();
        }
        return null;
    }
    protected void onPostExecute(String result) 
    {

        progressDialog.dismiss();
        Intent n = new Intent(firstactivity.this, secondactivity.class);
        startActivity(n);
    }
  }
Run Code Online (Sandbox Code Playgroud)

怎么叫这个

ProgressDialog progressDialog;
LongOperation mytask = null;
mytask = new LongOperation();
mytask.execute();
Run Code Online (Sandbox Code Playgroud)