Skip to content Skip to sidebar Skip to footer

Activity Class Being Called Before The Asynctask Finishes Background Process In Application Class

I have a class which extends Application class to load some data before any activity launches. I did some json parsing there, but the problem is the activity class is being called

Solution 1:

It's not good practice to start an activity and try to hold the onCreate event until data has been processed or received. Instead override the onPostExecute method in the AsyncTask which will be executed after doInBackground finish.

protected void onPostExecute(Void v) {
     // Add your code here !!!
 }

The reason you get a main thread exception on ICS is because you are running some network API (YouTubeParser) on the main UI thread.

Try this instead.

Thread t = new Thread(new Runnable() {
 public void run() {
       parser = new YouTubeParser(
            "http://powergroupbd.com/youtube/getyoutubejson.php");
    new ParserLoader().execute();
 }
}
t.start();

Post a Comment for "Activity Class Being Called Before The Asynctask Finishes Background Process In Application Class"