3

I want some view animation to occur after resuming my activity, but I can't succeed to catch the time after all the views loaded and the animation started before all the views loaded (before the animation transition). i tried to use onDraw, onWindowFocusChange, onResume, I discovered that onDraw is the last method on the life cycle of view but I still saw that the animation start before the user see the all the views

3 Answers3

4

Here is Android Activity lifecycle & Android View lifecycle tested on my device (Sony Z1 Compact)

Start an Activity
    Activity: onCreate
    Activity: onStart
    Activity: onResume
    View: onAttachedToWindow
    View: onWindowFocusChanged true
    # Running
    Activity: onPause
    View: onWindowFocusChanged false
    # Start to another Activity
    # Back from another Activity
    Activity: onResume
    View: onWindowFocusChanged true
    # Running
    View: onWindowFocusChanged false
    Activity: onPause
    Activity: onStop
    Activity: onDestroy
    View: onDetachedFromWindow

Turn Off Screen
    Activity: onCreate
    Activity: onStart
    Activity: onResume
    View: onAttachedToWindow
    View: onWindowFocusChanged true
    # Running
    Activity: onPause
    Activity: onStop
    View: onWindowFocusChanged false
    # Turn Off Screen
    # Turn On Screen
    Activity: onStart
    Activity: onResume
    View: onWindowFocusChanged true
    # Running
    View: onWindowFocusChanged false
    Activity: onPause
    Activity: onStop
    Activity: onDestroy
    View: onDetachedFromWindow

Switch Application
    Activity: onCreate
    Activity: onStart
    Activity: onResume
    View: onAttachedToWindow
    View: onWindowFocusChanged true
    # Running
    Activity: onPause
    View: onWindowFocusChanged false
    Activity: onStop
    # Switch to Application
    # Back from Application
    Activity: onStart
    Activity: onResume
    View: onWindowFocusChanged true
    # Running
    Activity: onPause
    View: onWindowFocusChanged false
    Activity: onStop
    Activity: onDestroy
    View: onDetachedFromWindow
Afrig Aminuddin
  • 772
  • 1
  • 9
  • 22
1

Consider using a Fragment instead of a view as fragments unless views have a life cycle. The life cycle is bound to their Activity where they are embedded.

See also: What is the benefit of using Fragments in Android, rather than Views?

Edit:

Try starting your animation delayed:

new Handler().post(new Runnable() {
    @Override
    public void run() {
        // Start your animation here.
    }
});
Community
  • 1
  • 1
Lars Blumberg
  • 19,326
  • 11
  • 90
  • 127
0

You can create a splash activity. In this splash activity you can show your animation.

How do I make a splash screen?

also if you need to calculate sth while it shows animation, use a thread to calculate and send it to your main activity

How do I pass data between Activities in Android application?

Community
  • 1
  • 1
bmavus
  • 892
  • 1
  • 7
  • 21
  • This has nothing to do with splash activity or with passing data between activities, I have an animation that I want to start the moment that the activity is visible to the user and the views are rendered. where ever I tried so far to put the start of the animation was too soon – user3863927 Sep 08 '14 at 08:42