Here is my Lottie animation code:
public class Splash extends AppCompatActivity {
ImageView logo,splashImg;
LottieAnimationView lottieAnimationView;
TextView textView;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,WindowManager.LayoutParams.FLAG_FULLSCREEN);
setContentView(R.layout.activity_splash);
logo = findViewById(R.id.logo);
splashImg = findViewById(R.id.img);
textView = findViewById(R.id.Motto);
lottieAnimationView = findViewById(R.id.lottie);
splashImg.animate().translationY(-2800).setDuration(1000).setStartDelay(4000);
logo.animate().translationY(1850).setDuration(1000).setStartDelay(4000);
textView.animate().translationY(1800).setDuration(1000).setStartDelay(4000);
lottieAnimationView.animate().translationY(1800).setDuration(1000).setStartDelay(4000);
}
}
And Now I want to go to another Activity, How do I do it??
CodePudding user response:
You can use the Handler class for this purpose and then navigate to your second or new Activity subclass by using Intent like so. In short this code will navigate to the other activity by waiting for 2000 milliseconds or 2 seconds which can be customised. Maybe you can add set it according to when your animation is done by selecting the duration of largest among all
new Handler().postDelayed(new Runnable(){
@Override
private void run(){
Intent intent = new Intent(Splash.this, YourNewActivity.class)
startActivity(intent)
}
}, 2000)
Another clean approach would to be add an AnimationListener and as soon as the animation completes just fire an Intent to start the other Activity
You can find how to use AnimationListener specially for Lottie here
CodePudding user response:
Please check this code:
mAddedToCartAnimation.addAnimatorListener(new Animator.AnimatorListener() {
@Override
public void onAnimationStart(Animator animation) {
Log.e("Animation:","start");
}
@Override
public void onAnimationEnd(Animator animation) {
startActivity(new Intent(this,NewActivity.class));
//Your code for remove the fragment
try {
getActivity().getSupportFragmentManager()
.beginTransaction().remove(this).commit();
} catch(Exception ex) {
ex.toString();
}
}
@Override
public void onAnimationCancel(Animator animation) {
Log.e("Animation:","cancel");
}
@Override
public void onAnimationRepeat(Animator animation) {
Log.e("Animation:","repeat");
}
});
