2011-01-24 98 views
0

这是我为我的启动画面代码:Android应用程序将不会打开

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(); 
    } 

不幸的是,应用程序将不会打开,也不会从闪屏进步。我不相信我使用的模拟器存在问题,所以它必须是这些代码中的某些内容妨碍它完全运行。有什么我失踪?

+4

这个问题很通用的,目前还不清楚代码是不会编译的,是抛出一个错误还是不像您期望的那样行事。告诉我们您的预期结果,以及您的实际结果与可能相关的任何logcat输出一起。 – 2011-01-24 23:28:31

+0

发布您的logcat日志,确切例外。 – 2011-01-25 00:39:13

回答

0

OnResume()将在onCreate()之后自动调用,因此您不需要在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(); 
} 
相关问题