Life cycle of view android
Asked Answered
L

3

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

Lynn answered 7/9, 2014 at 11:59 Comment(2)
post some code of your onCreate() and when you start the animation.Crosscheck
I start the animation on onDraw methodLynn
O
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
Oar answered 22/8, 2017 at 14:9 Comment(1)
This is very helpful, because it shows the View's actual lifecycle, not just the first half like most documentation I've found. Thank you.Dunker
M
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.
    }
});
Matildematin answered 7/9, 2014 at 12:32 Comment(5)
My view is already in a fragment, this is not relevant to my question at all.Lynn
So why don't you then forward the Fragment lifecycle calls to your view?Matildematin
because I see the animation after it started when I put my animation on onDraw() nethodLynn
In my implement I do it but the problem still occurLynn
I guess without posting your code, nobody can assist youMatildematin
B
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?

Bailly answered 7/9, 2014 at 12:35 Comment(1)
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 soonLynn

© 2022 - 2024 — McMap. All rights reserved.