Life cycle of view android

痞子三分冷 提交于 2020-01-13 16:44:48

问题


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


回答1:


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



回答2:


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.
    }
});



回答3:


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?



来源:https://stackoverflow.com/questions/25709919/life-cycle-of-view-android

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!