Вопрос

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:

Activity lifecicle

Thanks!

Это было полезно?

Решение

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.

Другие советы

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
}

You can start your animation in onPostResume(), which is invoked after onResume() finished.

Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top