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
Life cycle of view android
Asked Answered
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
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
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.
}
});
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() nethod –
Lynn
In my implement I do it but the problem still occur –
Lynn
I guess without posting your code, nobody can assist you –
Matildematin
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?
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 –
Lynn
© 2022 - 2024 — McMap. All rights reserved.
onCreate()
and when you start the animation. – Crosscheck