这是我的闪屏代码:
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();
}不幸的是,应用程序不会打开,也不会从闪屏中运行。我不认为我正在使用的仿真器有问题,所以一定是代码中的某些东西阻止了它完全运行。我是不是遗漏了什么?
发布于 2011-01-25 07:37:25
OnResume()将在onCreate()之后自动调用,所以您不需要在onCreate中调用startAnimating()。行SplashScreenPear.this.finish();可能不会被调用-但我不能百分之百确定这一点。
如果不知道你所说的不会运行-不会编译,我就不能告诉你更多?给出一个运行时异常?只有一个黑屏?
Edit:您还将在onPause方法期间添加list ener --该方法不会被调用...这段代码的buggy会更少,效率会更高:
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();
}https://stackoverflow.com/questions/4788364
复制相似问题