java - Starting activity on mouse click makes animation slow -
so developing android application in have home screen , screen content of app. on home screen have button navigates user content's screen (actually image view used button). when clicked button should start animation of being clicked , start activity of content screen. works pretty bad , slow, when click button animation starts slows down (lags). tried changing event click tap , lots of other possible solutions none worked. tried commenting "startactivity" method , fixed it, animation running smoothly. need startactivity method, best approach here, how can fix this. can putting startactivity in different thread work, i'm not sure how if well
this code:
((button)findviewbyid(r.id.btnplay)).setonclicklistener(new view.onclicklistener() { @override public void onclick(final view v) { //shake.reset(); findviewbyid(r.id.btnplay).startanimation(shake); shake.setanimationlistener(new animation.animationlistener() { intent i; @override public void onanimationstart(animation animation) { = new intent(v.getcontext(), gameactivity.class); startactivity(i); } @override public void onanimationend(animation animation) { ((button) findviewbyid(r.id.btnplay)).setvisibility(view.invisible); } @override public void onanimationrepeat(animation animation) { } }); } }); shake animation loaded custom xml file. have same animation in content screen , runs smoothly, of course there no startactivity there. here code:
<set xmlns:android="http://schemas.android.com/apk/res/android"> <rotate android:duration="70" android:fromdegrees="-5" android:pivotx="50%" android:pivoty="50%" android:repeatcount="5" android:repeatmode="reverse" android:interpolator="@android:anim/linear_interpolator" android:todegrees="5" /> <translate android:fromxdelta="-10" android:toxdelta="10" android:repeatcount="5" android:repeatmode="reverse" android:interpolator="@android:anim/linear_interpolator" android:duration="70" />
move these lines of code in onanimationend()
i = new intent(v.getcontext(), gameactivity.class); startactivity(i); update
i've tried code , works me:
animation animation = animationutils.loadanimation(myapplication.getappcontext(), r.anim.shake); public void onclick(view v) { if (v.getid() == r.id.btnplay) { animation.setanimationlistener(new animation.animationlistener() { @override public void onanimationstart(animation animation) { } @override public void onanimationend(animation animation) { intent intent = new intent(getactivity(), articleactivity.class); startactivity(intent); } @override public void onanimationrepeat(animation animation) { } }); v.startanimation(animation); } } if activity starts when animation of button starts, there many things (like: button animation, execution of activity lifecycle methods including lifecycle methods of fragments, animation used transition between activities) executed on main thread => button animation stuck (the animation won't smooth).
Comments
Post a Comment