0

我已经在我的 AsyncTask 中与服务器进行了一些通信。现在,根据该数据,我想转到屏幕 A 或屏幕 B。正确的方法是什么?

我应该在 postExcute 部分调用新活动吗?我目前在启动画面上。

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


        protected void onPreExecute() {
                //does stuff before excuting code
        }

        //does the main operation
        protected String doInBackground(Void... params)  {

            publishProgress("10", "Checking Login Details Exist . . .");

            if(checkForLogin()){    
                //validate with DB
                publishProgress("20", "Logging in, verifying . . .");
                if(sendforVerif()){
                    publishProgress("100", "You Are Logged In!");

                }else{                  
                    publishProgress("100", "Error Logging In.");

                }

            }else{
                //login or registration required
                publishProgress("100", "Login Required . . .");
            }

            return null;
        }

        //Update Progress       
        protected void onProgressUpdate(String... values) {
            mProgress.setProgress(Integer.parseInt(values[0]));
            statusReadout.setText(values[1]);
        }

        //Update UI with results
        protected void onPostExecute() {
            Intent intent = new Intent(SplashScreen.this, MenuScreen.class);
            SplashScreen.this.startActivity(intent);
        }

    }

我不认为这是正确的,而且它不起作用!?

TIA

4

1 回答 1

2

目前,您没有覆盖将代码更改为的onPostExecute方法:AsyncTask

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

@Override
    protected void onPreExecute() {
            //does stuff before excuting code
    }

    //does the main operation
@Override
    protected String doInBackground(Void... params)  {

             // your code here...
        return null;
    }

    //Update Progress 
@Override     
    protected void onProgressUpdate(String... values) {
  // your code here...
    }
   @Override
    protected void onPostExecute(String result ) {
        Intent intent = new Intent(SplashScreen.this, MenuScreen.class);
        SplashScreen.this.startActivity(intent);
    }

}
于 2013-02-25T23:37:58.727 回答