繁体   English   中英

Android应用无法打开

[英]Android app won't open

这是我的初始屏幕代码:

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

不幸的是,该应用程序无法打开,也不会从启动屏幕继续运行。 我不相信我使用的仿真器有问题,因此该代码中一定有一些问题阻止了它的完全运行。 我有什么想念的吗?

无论如何,onResume()将在onCreate()之后自动调用,因此您无需在onCreate中调用startAnimating()。 行SplashScreenPear.this.finish(); 可能不会被称为-尽管我对此不确定100%。

我不能不告诉您更多信息,否则它将无法运行-无法编译? 给运行时异常? 只是黑屏?

编辑:您还将在onPause方法中添加列表发生器-不会被调用...此代码将减少错误,并且效率更高:

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM