Note that there are some explanatory texts on larger screens.

plurals
  1. POaccessing view components after startActivity() in ASyncTask
    text
    copied!<p>I have an AsyncTask which retrieves data from a server and then needs to start a new Activity to display the data.</p> <p>doing this within the ASync onPostExecute works... (but doesn't start the new activity)</p> <pre><code>setContentView(R.layout.activity_list); TextView textListDate = ((TextView)findViewById(R.id.textListDate)); textListDate.setText(FormatUtilities.formatDateLong(list.getDateFor())); </code></pre> <p>doing this results in a null pointer exception (due to TextListDate being null</p> <pre><code>Intent in = new Intent(super.getAppContext(), List.class); in.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); super.getAppContext().startActivity(in); TextView textListDate = ((TextView)findViewById(R.id.textListDate)); textListDate.setText(FormatUtilities.formatDateLong(list.getDateFor())); </code></pre> <p>and doing this results in a screen loading with what i want, and then being blanked almost immediatley...</p> <pre><code>Intent in = new Intent(super.getAppContext(), List.class); in.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); super.getAppContext().startActivity(in); setContentView(R.layout.activity_list); TextView textListDate = ((TextView)findViewById(R.id.textListDate)); textListDate.setText(FormatUtilities.formatDateLong(list.getDateFor())); </code></pre> <p>any suggestions on what I am missing? I assume it is something to do with findViewById trying to access the view of the "current" activity and not the new one...</p> <p>Do i somehow need to pass my data to the new Activity and do the findViewById inside the next activity?</p> <p>thanks for the help.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload