title: In Android, How do I change the TextView from an AsyncTask?
body: <p>I have a splash screen with a TextView to displays what the app is doing such as "Updating Library"... "Updating Shipping"... etc. I'm using AsyncTask to updated my database via an API.</p>
  
  <p>I'm passing the update text to the AsyncTask. I need to change the text in <code>TextView statusMessage</code>. I'm attempting to do this:</p>
  
  <pre><code>public class JSONParser extends AsyncTask&lt;String, String, JSONObject&gt; {
  
      static InputStream is = null;
      static JSONObject json = null;
      static String outPut = "";
  
      TextView statusMessage;
  
      @Override
      protected void onPreExecute() {
          statusMessage = (TextView) findViewById(R.id.statusMessage);
  
      }
  
  ...
  </code></pre>
  
  <p>My plan is to change the text in the <code>doInBackground</code> method but <code>findViewById</code> isn't accessible in AsyncTask. I think I need to use <code>setContentView</code> to allow <code>findViewById</code> to work but I'm not sure how.</p>
  
  <p>My java file is <code>SplashScreen.java</code> and my xml is <code>activity_splash_screen.xml</code></p>
  
  <p>----- EDIT -----</p>
  
  <p>For more info I have three pieces talking to each other:</p>
  
  <p>SplashScreen.java -> calls to method in baseActivity.java -> method sends data to JSONParser.java -> sends parsed JSON from the API to baseActivity.java to update database</p>
  
  <p>Per suggestions below I've declared </p>
  
  <p><code>statusMessage = (TextView) findViewById(R.id.statusMessage);</code></p>
  
  <p>In baseActivity.java's onCreate since it's the file calling the AsyncTask.</p>
  
  <p>In JSONParser.java I've done this, now:</p>
  
  <pre><code>public class JSONParser extends AsyncTask&lt;String, String, JSONObject&gt; {
  
      static InputStream is = null;
      static JSONObject json = null;
      static String outPut = "";
  
      TextView statusMessage;
  
      @Override
      protected JSONObject doInBackground(String... params) {
          // TODO Auto-generated method stub
      ...
      }
  
  
      protected void onProgressUpdate() {
          statusMessage.setText("testing");
       }
  
      protected void onPostExecute(JSONObject result) {
  
  
      }
  }
  </code></pre>
  
  <p>I'm just using "testing" there for testing purposes.</p>