0

The animation on the first activity does not work when I use startActivity and I don't know it's strange.

public class MainActivity extends AppCompatActivity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); getSupportActionBar().hide(); ImageView img = (ImageView) findViewById(R.id.splash); img.animate().scaleX(0.6f).scaleY(0.6f).rotation(1080f).setDuration(2000); Intent intent = new Intent(getApplicationContext(), NextActivity.class); startActivity(intent); } } 
3
  • post the stacktrace Commented Dec 11, 2016 at 17:12
  • there is no error or exception it's like it ignores all animations when i put the last line startActivity(intent); and when i remove it , it works fine Commented Dec 11, 2016 at 17:15
  • 1
    how should it work if you directly start another activity....? If you want an animation for switching activities, you should use overridePendingTransition Commented Dec 11, 2016 at 17:16

4 Answers 4

1

Use this.

 private Handler handlerImage; private Runnable runnableImage; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); getSupportActionBar().hide(); ImageView img= (ImageView) findViewById(R.id.splash); img.animate().scaleX(0.6f).scaleY(0.6f).rotation(1080f).setDuration(2000); handlerImage = new Handler(); runnableImage = new Runnable() { @Override public void run() { Intent intent=new Intent(getApplicationContext(),NextActivity.class); startActivity(intent); } }; handlerImage.postDelayed(runnableImage, 3000); } @Override protected void onDestroy() { super.onDestroy(); if (handlerImage != null) { handlerImage.removeCallbacks(runnableImage); } } 
Sign up to request clarification or add additional context in comments.

Comments

0

I hope you are trying to show a scale and rotation animation of your APP logo for sometime and then trying to launch Another Activity.

Since you are starting Another activity ,Before Starting Animation on the Imageview, ActivityManager will switch to the Next Animation, and hence you are not able to see the Animation, Solution is to set an Animationlistner to the ViewPropertyAnimator object given to ImageView and Start the main Activity on onAnimationEnd() callback.

code snippet is given below:

 img.animate().scaleX(0.6f).scaleY(0.6f).rotation(1080f).setDuration(2000).setListener(new AnimatorListener() { @Override public void onAnimationStart(Animator animation) { // TODO Auto-generated method stub } @Override public void onAnimationRepeat(Animator animation) { // TODO Auto-generated method stub } @Override public void onAnimationEnd(Animator animation) { Intent intent=new Intent(getApplicationContext(),NextActivity.class); startActivity(intent); } @Override public void onAnimationCancel(Animator animation) { // TODO Auto-generated method stub } }); 

1 Comment

Thanks man , Thanks to you I know now why and it worked just fine
0

Check this,

Intent intent=new Intent(this,NextActivity.class); startActivity(intent); 

Comments

0

@Zakaria Ait Ouchrif,

You can use the method of Activity overridePendingTransition() with two xml of in and out Animation.

You can define simple transition animations in an XML resource file.

Also you can refer this tutorial for same.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.