飞溅屏幕不会破坏自己? Java的

时间:2012-03-12 03:51:33

标签: android splash-screen onpause

起初我的启动画面工作得很好,但是后来我试图放入一个会破坏活动效果的代码。我通过将onPause方法放入受保护的void的末尾来完成此操作。

这是放入方法之前的启动画面

'package com.shipment.emulatorfix;

'import android.app.Activity;
'import android.content.Intent;
'import android.media.MediaPlayer;
'import android.os.Bundle;

'public class Splash extends Activity{


@Override
protected void onCreate(Bundle savedInstanceState) {
    // TODO Auto-generated method stub
    super.onCreate(savedInstanceState);
    setContentView(R.layout.splash);
    Thread timer = new Thread(){
        public void run(){
            try{
                sleep(5000);
            } catch(InterruptedException e){
                e.printStackTrace();
            }finally{
                Intent openMain = new Intent("android.intent.action.TESTINGEMULATORACTIVITY");
                startActivity(openMain);
            }
        }
    };
timer.start();
}



'}

这是后代码

'package com.shipment.emulatorfix;

'import android.app.Activity;
'import android.content.Intent;
'import android.media.MediaPlayer;
'import android.os.Bundle;

'public class Splash extends Activity{


@Override
protected void onCreate(Bundle savedInstanceState) {
    // TODO Auto-generated method stub
    super.onCreate(savedInstanceState);
    setContentView(R.layout.splash);
    Thread timer = new Thread(){
        public void run(){
            try{
                sleep(5000);
            } catch(InterruptedException e){
                e.printStackTrace();
            }finally{
                Intent openMain = new Intent("android.intent.action.TESTINGEMULATORACTIVITY");
                startActivity(openMain);
            }
        }
    };
timer.start();
}

@Override
protected void onPause() {
    // TODO Auto-generated method stub
    super.onPause();
    finish();
}

'}

非常感谢任何帮助,谢谢。

4 个答案:

答案 0 :(得分:2)

试试这个

public class SplashScreen extends Activity {

protected int _splashTime = 2000;   
private Thread splashTread;

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.splash);        

    splashTread = new Thread() {
        @Override
        public void run() {
            try {                   
                synchronized(this) {
                    wait(_splashTime);
                }                   
            } catch(InterruptedException e) {
                System.out.println("EXc=" + e);
            } 
            finally {              

                startActivity(new Intent(SplashScreen.this, Login.class ));                 
                //stop();
                finish();
            }
        }
    };      
    splashTread.start();
  }
}

答案 1 :(得分:0)

public class Welcome extends Activity
{
 /** Called when the activity is first created. */
    Handler mHandler,actHandler;          

   @Override
      public void onCreate(Bundle savedInstanceState)
     {
     super.onCreate(savedInstanceState);        
     setContentView(R.layout.welcome);

    new Thread(){
       public void run(){
       try{                
          Thread.sleep(3000);                 
          }                               
       catch(Exception ex){

          Log.e("Welcome Exception :",ex.toString());
          }
              try{
                 Message msg=mHandler.obtainMessage();  
                 mHandler.sendMessage(msg);     
                 }
                 catch(NullPointerException ex){
                 Log.e("Handler Exception :",ex.toString());                                                         
                }                       
              }

    }.start(); 
      mHandler=new Handler(){
        public void handleMessage(Message msg){
        super.handleMessage(msg);                


        Intent i=new Intent(Welcome.this,M_chat.class);
        startActivity(i);
        finish();
        }
        };  
      }   
  }

答案 2 :(得分:0)

完成活动,然后开始其他活动。

Thread timer = new Thread(){
    public void run(){
        try{
            sleep(5000);
        } catch(InterruptedException e){
            e.printStackTrace();
        }finally{
            finish();
            Intent openMain = new Intent("android.intent.action.TESTINGEMULATORACTIVITY");
            startActivity(openMain);
        }
    }
};

答案 3 :(得分:0)

这应该适合你。

@Override
protected void onCreate(Bundle savedInstanceState) {
    // TODO Auto-generated method stub
    super.onCreate(savedInstanceState);
    setContentView(R.layout.splash);
    Thread timer = new Thread() {
        public void run() {
            try {
                sleep(5000);
            } catch(InterruptedException e){
                e.printStackTrace();
            } finally {
                Intent openMain = new  Intent("android.intent.action.TESTINGEMULATORACTIVITY");
                startActivity(openMain);
                Splash.this.finish();
            }
        }
    };
    timer.start();
}