Reputation: 610
What's best practice for structuring an activity, which should begin by displaying an animated image, and then move to another "activity" by intent when the animation is complete? I understand some of the basic principles, but I am getting lost on structuring the flow here.
public class Scanimation extends Activity {
//create name of animation
Animation myFadeInAnimation;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.scanning_view);
//grab the imageview from the layout, and then load the animation listener
ImageView myImageView = (ImageView) findViewById(R.id.blinkingView01);
AnimationListener al= new AnimationListener() {
public void onAnimationStart(Animation animation) {
// do nothing
}
public void onAnimationRepeat(Animation animation) {
// do nothing
}
// at the end of the animation, start new activity
public void onAnimationEnd(Animation animation) {
Intent myIntent = new Intent (view.getContext(), LastActivity.class);
startActivity(myIntent);
}
// get the animation effects which are in the XML file and defines how to animate it Animation myFadeInAnimation = AnimationUtils.loadAnimation(this, R.anim.fade_in);
};
//okay now start the animation on screen
myImageView.startAnimation(myFadeInAnimation);
// go get the vibration service and vibrate quickly while screen is animated
Vibrator v = (Vibrator) getSystemService(Context.VIBRATOR_SERVICE);
long milliseconds = 2000;
v.vibrate(milliseconds);
long[] pattern = { 500, 300 };
v.vibrate(pattern, -1);
}
}
Most of the tutorials I've read appear to use this type of flow. I'm pulling in my main layout and view, then animating the specific view as well as vibrating the device for a quick second. At the end of the animation, the intent to start my next or last activity does not fire.
What am I missing here?
Upvotes: 1
Views: 2755
Reputation: 610
Here's the corrected version:
public class Scanimation extends Activity implements AnimationListener{
public Animation myFadeInAnimation;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.scanning_view);
ImageView myImageView = (ImageView) findViewById(R.id.blinkingView01);
myFadeInAnimation = AnimationUtils.loadAnimation(this, R.anim.fade_in);
myFadeInAnimation.setAnimationListener(this);
myImageView.startAnimation(myFadeInAnimation);
}
public void onAnimationEnd(Animation animation) {
Intent myIntent = new Intent (this, Lastactivity.class);
startActivity (myIntent);
}
public void onAnimationRepeat(Animation animation) {
}
public void onAnimationStart(Animation animation) {
// go get the vibrator service
Vibrator v = (Vibrator) getSystemService(Context.VIBRATOR_SERVICE);
// 1. Vibrate for 2000 milliseconds
long milliseconds = 2000;
v.vibrate(milliseconds);
// 2. Vibrate in a Pattern
long[] pattern = { 500, 300 };
v.vibrate(pattern, -1);
}
}
Upvotes: 2
Reputation: 1006759
I do not see where you are calling setAnimationListener()
to associate al
with myFadeInAnimation
. Of course, I don't see where you are actually creating myFadeInAnimation
, either.
Upvotes: 2