首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Android应用程序无法打开

Android应用程序无法打开
EN

Stack Overflow用户
提问于 2011-01-25 07:24:21
回答 1查看 364关注 0票数 0

这是我的闪屏代码:

代码语言:javascript
复制
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();
     }

不幸的是,应用程序不会打开,也不会从闪屏中运行。我不认为我正在使用的仿真器有问题,所以一定是代码中的某些东西阻止了它完全运行。我是不是遗漏了什么?

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2011-01-25 07:37:25

OnResume()将在onCreate()之后自动调用,所以您不需要在onCreate中调用startAnimating()。行SplashScreenPear.this.finish();可能不会被调用-但我不能百分之百确定这一点。

如果不知道你所说的不会运行-不会编译,我就不能告诉你更多?给出一个运行时异常?只有一个黑屏?

Edit:您还将在onPause方法期间添加list ener --该方法不会被调用...这段代码的buggy会更少,效率会更高:

代码语言:javascript
复制
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();
 }
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/4788364

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档