Reputation: 380
I'd like to start an animation right after an activity is created. The problem is that I have to call the method once everything is showed on the screen, let's say one second after being showed for the first time.
In other words, I'm looking for a method to be executed right after onCreate() but after the activity is shown:
Thanks!
Upvotes: 0
Views: 370
Reputation: 69208
You can start your animation in onPostResume(), which is invoked after onResume() finished.
Upvotes: 1
Reputation: 3452
You can't assume that the GUI has been drawn in onCreate(). In fact it often is not.
The best way to catch when everything has finally be rendered on screen is with:
@Override
public void onWindowFocusChanged (boolean hasFocus) { ... }
Put your thing in a timer here.
Upvotes: 1
Reputation: 44571
Assuming you set up your layout
in onCreate()
it looks like you can use setStartTime(long millis) on your animation object.
public void onCreate(...)
{
super.onCreate(...);
setContentView(R.layout.your_layout);
// do whatever else you need to
// create your animation
animation.setStartTime(1000); // should start it in one second
}
Upvotes: 1