This is my activity(snippet):
setContentView(R.layout.main)
//Some Time consuming code
As you can see the time consuming code is placed after the setcontentview. This activity takes a lot of time to load. to confirm I removed the time consuming code and the activity is displayed very quickly.My question is I am doing the time consuming work only after setContentView the layout, then why does it take so much time to display at least the layout .
The app is running on a single thread UI thread. It cannot show the view until it has finished running everything else.
You need to use an
AsyncTaskor a thread for any time consuming code. Have a look at this: http://developer.android.com/resources/articles/painless-threading.html