0

I'm trying to use doInBackground method of AsyncTask to send a message to a webserver. Then use the onPreExecute() and onPostExecute(String result) methods of AsyncTask to change a text control from sending data to Fineshed.

The issue is that Inside the AsyncTask String class I cannot access any of the variables declared in the outside class. Thus I cannot change my TextView inside these methods. I get, so mSEnd.setText("Sending data")gives me mSend undefined.

Is there a way to use the variables I declare in my outside class?

public class EndOfWorldActivity  extends cBase  implements OnClickListener {

     TextView textCountDown;
     TextView textPercent;

  public void onClick(View v) {
        Intent i;
        switch(v.getId())
        {

        case R.id.butVote3:
                 // Start ASync Task
             new SendTextOperation().execute("");     
            break;


        case R.id.buGame:
                 // Start ASync Task
             new SendTextOperation().execute("");  
        break;
        }
    }


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

        @Override
        protected void onPreExecute() {

          //Update UI here
          mSEnd undefined error
          mSend.setText("Sending your vote to server");
          mSend.invalidate();
        }

        @Override
        protected String doInBackground(String... params) {
              // Talk to server here to avoid Ui hanging 
              // talk to server method undefined                 
              TalkToServer( mYes[mPes-1] );
              return null;
        }      

        @Override
        protected void onPostExecute(String result) {  
              // Update screen here after talk to server end

                  UpdateScreen(); 
                  mSend .setText("");
        }

  }
} // end of class
AndroidLearner
  • 4,500
  • 4
  • 31
  • 62
Ted pottel
  • 6,869
  • 21
  • 75
  • 134

2 Answers2

0

use

new SendTextOperation().execute();

instead of this

new SendTextOperation().execute("");
Husam A. Al-ahmadi
  • 2,056
  • 2
  • 20
  • 27
0

There is a complete example given in the link below.

The application send HTTP query to a web server and get back the content of the query :

Example: Android bi-directional network socket using AsyncTask

Community
  • 1
  • 1