Home > Blockchain >  Animation is not playing in onCreate
Animation is not playing in onCreate

Time:12-09

I am using the app's layout animation in onCreate, The basic logic is that every odd number app will show a screen to the user to purchase the premium of the app.

But calling the same function in onCreate messes up the rest of the app.

I am calling this code in onCreate

 int val = PrefrencesClass.getIntPreference(mContext, Constants.APPSPREF, Constants.APPCOUNT);
    if ((val % 2) == 0) {
        ShowViewToUp(rl_premium);
    }
    val  ;
    PrefrencesClass.setIntPreference(mContext, Constants.APPSPREF, Constants.APPCOUNT, val);

Here is ShowViewToUp Function

   private void ShowViewToUp(View view) {
    Animation animation2 = AnimationUtils.loadAnimation(mContext,
            R.anim.bottom_up);
    animation2.setDuration(500);
    view.startAnimation(animation2);
    view.setVisibility(View.VISIBLE);
}

When this function is called from onCreate or listeners of the in-app purchase billing function, the rest of the app stops working, values will not be assigned and no layouts will initialize, etc.

CodePudding user response:

I fixed the issue using Runnable in ShowViewToUp Function

    private void ShowViewToUp(View view) {
    view.post(new Runnable() {
        @Override
        public void run() {

            Animation animation2 = AnimationUtils.loadAnimation(mContext,
                    R.anim.bottom_up);
            animation2.setDuration(500);
            view.startAnimation(animation2);
            view.setVisibility(View.VISIBLE);
        }
    });
}
  • Related