Mithun Sreedharan
Mithun Sreedharan

Reputation: 51272

Android call back after layout rendering has completed?

How can i create/bind a service only after activity layout is rendered?

-- Update

I have two tabs (both as separate activities)on the main activity and the data used for tabs comes from Service. Right now i'm binding service inside onCreate method. Issue is that layout is not rendered till all the statements inside the onCreate gets finished. A blank screen is shown till the service get bind

Upvotes: 11

Views: 20723

Answers (2)

Edward Falk
Edward Falk

Reputation: 10083

See ViewTreeObserver

More info here: https://stackoverflow.com/a/7735122/338479

Upvotes: 2

James
James

Reputation: 2376

Put the call to create/bind the service at the end of your onCreate activity. If it must absolutely bind/create at the very end of the process, you can add a boolean flag to your activity indicating whether you are already bound or have already created the service. You could then override onResume() as follows:

@Override
public void onResume() {
     super.onResume();
     if (!flag) {
          // Call code to bind/create the service.
     }
 }

Upvotes: 0

Related Questions