Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to correctly start activity from PostExecute in Android?
    primarykey
    data
    text
    <p>I have an AsyncTask, that fills a custom List with parsed data from Internet. </p> <p>In PostExecute I fill that List and get it ready to transfer it to a new Activity. </p> <p>I do it this way:</p> <pre><code>@Override protected void onPostExecute(List&lt;VideoDataDescription&gt; result) { super.onPostExecute(result); MainActivity.progressDialog.dismiss(); context.startActivity(new Intent(context, ResultsQueryActivity.class)); } </code></pre> <p>where context</p> <pre><code> private Context context; </code></pre> <p>In LogCat after executing this code I get a Java.lang.NullPointerException. Is this possible and correct to start an Activity as I do it?</p> <p><strong>UPD</strong> I have added</p> <pre><code> private Context mContext; public YoutubeAndYahooParser(Context context) { super(); this.mContext = context; } </code></pre> <p>to initialize context and call </p> <pre><code>YoutubeAndYahooParser youtubeAndYahooParser = new YoutubeAndYahooParser(ResultsQueryActivity.this); youtubeAndYahooParser.execute("my string to pass in asynctak"); </code></pre> <p>After this in PostExecute</p> <pre><code>Intent intent = new Intent(mContext, ResultsQueryActivity.class); intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); mContext.startActivity(intent); </code></pre> <p>I added new flag because of I have got in LogCat the next:</p> <p>*Calling startActivity() from outside of an Activity context requires the FLAG_ACTIVITY_NEW_TASK flag. Is this really what you want?*</p> <p>Am I right?</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
 

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