这是我的启动画面的代码:
public class SplashScreenPear extends Activity {
/** Called when the activity is first created. */
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.pear);
startAnimating();}
private void startAnimating(){
ImageView pearfade = (ImageView) findViewById(R.id.pearish);
Animation pearfadeact = AnimationUtils.loadAnimation(this, R.anim.fadein);
pearfade.startAnimation(pearfadeact);}
@Override
protected void onPause() {
super.onPause();
ImageView pearfade = (ImageView) findViewById(R.id.pearish);
pearfade.clearAnimation();
Animation pearfadeact = AnimationUtils.loadAnimation(this, R.anim.fadein);
pearfadeact.setAnimationListener(new AnimationListener() {
public void onAnimationEnd(Animation animation) {
// The animation has ended, transition to the Main Menu screen
startActivity(new Intent(SplashScreenPear.this, Unicorn.class));
SplashScreenPear.this.finish();
}
public void onAnimationRepeat(Animation animation) {
}
public void onAnimationStart(Animation animation) {
}
});
}
@Override
protected void onResume() {
super.onResume();
startAnimating();
}
不幸的是,应用程序无法打开,并且它不会从启动画面进展。我不相信我正在使用的模拟器存在问题,因此必须在此代码中阻止其完全运行。有什么我想念的吗?
答案 0 :(得分:0)
OnCesate()之后将自动调用OnResume(),因此您不需要在onCreate中调用startAnimating()。 SplashScreenPear.this.finish()行;可能没有被召唤 - 虽然我不是100%肯定的。
如果不知道你的意思,我不能告诉你更多不会运行 - 不会编译?给出运行时异常?只是黑屏?
编辑:您还在onPause方法中添加了列表ener - 这将不会被调用... 此代码将减少错误并提高效率:
package com.unicorn.test.whee;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.animation.Animation;
import android.view.animation.Animation.AnimationListener;
import android.view.animation.AnimationUtils;
import android.widget.ImageView;
public class SplashScreenPear extends Activity {
ImageView pearfade;
/** Called when the activity is first created. */
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.pear);
ImageView pearfade = (ImageView) findViewById(R.id.pearish);
}
private void startAnimating(){
Animation pearfadeact = AnimationUtils.loadAnimation(this, R.anim.fadein);
pearfadeact.setAnimationListener(new AnimationListener() {
public void onAnimationEnd(Animation animation) {
// The animation has ended, transition to the Main Menu screen
startActivity(new Intent(SplashScreenPear.this, Unicorn.class));
SplashScreenPear.this.finish();
}
public void onAnimationRepeat(Animation animation) {
}
public void onAnimationStart(Animation animation) {
}
});
pearfade.startAnimation(pearfadeact);
}
@Override
protected void onPause() {
super.onPause();
pearfade.clearAnimation();
}
@Override
protected void onResume() {
super.onResume();
startAnimating();
}