简体   繁体   中英

Android app won't open

This is my code for my splash screen:

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

Unfortunately the application won't open, and it won't progress from the splash screen. I don't believe there is a problem with the emulator that I'm using so it must be something in this code that is preventing it from fully running. Is there anything I am missing?

OnResume() will be called automatically after onCreate() anyway, so you shouldn't need to put a call to startAnimating() in onCreate. The line SplashScreenPear.this.finish(); might not be called- I'm not 100% certain on this though.

I can't tell you more without knowing what you mean by it won't run- won't compile? Gives a run time exception? Just a black screen?

Edit: You are also adding the list ener during the onPause method- which isn't going to be called... This code will be less buggy and more efficient:

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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