Closed frankenten13 closed 5 years ago
Hi Frankenten13,
This is happening because during the onCreate the button didn't draw it self yet, so it doesn't know the measures that it needs to know before animating...
I can work on a fix to this problem, but first could you explain me a bit better what are you trying to do with the button? Do you need to call the animation with a delay or you need to start your activity the the loading animation?
Thanks for your quick reply, i have a layout Login with funcion auto login when user and password already input, so i need call startAnimation on onCreate. Here my code.
if(!mEtUser.getText().equals("")&& !mEtPassword.getText().equals("")){
mBtLogin.startAnimation();
}
Perfect if i can call it on onCreate. Thanks & best regards
I will fix that in this next week
@leandroBorgesFerreira, sorry to disagree, but this doesn't require much of a fix. onCreate()
is not supposed to be used for animating things nor explicit app logic (such as Login) as this can lead to several issues such as lagging due to early fired GC's and others. @frankenten13, you should read about the activity lifecycle and when are you supposed to invoke certain parts of your code. Invoking a Login function during onCreate()
is a pretty terrible design decision; you are delaying your activity creation process.
As per Android documentation:
In the onCreate() method, you perform basic application startup logic that should happen only once for the entire life of the activity.
When using a ViewModel and LiveData, you set up LiveData Observers in onCreate. So if the Button animation is controlled by the ViewModel, the log in is already started and the device is rotated, the observer will immediately fire from the onCreate method.
This problem was already fixed. The button accepts animation commands before the screen get drawn and waits for the right time for the animation to start.
Beautiful animation. I have a problem when init call mBtLogin.startAnimation(), animation not load full in onCreate. I fix it as put startAnimation in a Handler().postdelay. How to direct call startAnimation() when start app. Thanks.