I need to download an image from internet inside oncreate method of second activity in my app. I know that accessing internet on main thread causes android.os.NetworkOnMainThreadException on 3.x and higher versions. Instead of downloading the image in a background thread in second activity, Can i start that activity from a background thread? I mean, can i use the below line inside doInbackground() method of AsyncTask class.
startActivity(new Intent(FirstActivity.this, SecondActivity.class));
Will it work on 3.x ? or Will it give the same exception ?
I don’t have 3.x device. Sorry.
What you can do is to start the second activity normally and then, in the onCreate() method of your second activity, start an AsyncTask that downloads the image in doInBackground and then show the image in the onPostExecute method.