0
Thread th = new Thread(){
    public void run()
    {
        try{
            sleep(5000);
        }
        catch(InterruptedException e){
            e.printStackTrace();
            
        }
        finally{    
            Intent openMainActivity = new Intent("com.askselva.simple.MENU");
            startActivity(openMainActivity);
        }
        
    }   
};
th.start();               //Error -1

错误 1:令牌“开始”上的语法错误,此令牌后应有标识符

4

5 回答 5

0

你也可以试试这个:)

package com.askselva.simple;
import android.app.Activity;
import android.content.Intent;
import android.media.MediaPlayer;
import android.os.Bundle;
public class Splash extends Activity{
MediaPlayer ourSong;
  @Override
  protected void onCreate(Bundle selvaLovesKumar){
    // TODO Auto-generated method stub
    super.onCreate(selvaLovesKumar);
    setContentView(R.layout.splash);
    ourSong=MediaPlayer.create(Splash.this, R.raw.airtel);
    ourSong.start();

    new Thread(new Runnable()){
      public void run(){
        try{
            sleep(5000);
        }
        catch(InterruptedException e){
            e.printStackTrace();
        }
        finally{    
            Intent openMainActivity = new Intent("com.askselva.simple.MENU");
            startActivity(openMainActivity);
        }
      } 
    }.start();        
  }
  @Override
  protected void onPause(){
    // TODO Auto-generated method stub
    super.onPause();
    finish();
    ourSong.release();
  }
 }
于 2013-09-17T11:15:10.903 回答
0

你的th.start();陈述应该出现在你Activity班级的某个方法中。你不能把它放在活动的某个地方。

在您的情况下,它可以进入OnCreate()方法,但线程创建必须在您start那里的线程之前完成。

于 2013-09-17T10:02:40.753 回答
0

问题是,你不应该th.start()在你的类方法之外使用你的方法。你不能像那样随意地把它放在你的班级里。

于 2013-09-17T10:04:43.937 回答
0

尝试这个

package com.askselva.simple;
import android.app.Activity;
import android.content.Intent;
import android.media.MediaPlayer;
import android.os.Bundle;
public class Splash extends Activity {
    MediaPlayer ourSong;
    @Override
    protected void onCreate(Bundle selvaLovesKumar) {
        super.onCreate(selvaLovesKumar);
        setContentView(R.layout.splash);
        ourSong=MediaPlayer.create(Splash.this, R.raw.airtel);
        ourSong.start();

        Thread th = new Thread(){
        public void run()
        {
            try{
                sleep(5000);
            }
            catch(InterruptedException e){
                e.printStackTrace();
            }
            finally{    
                Intent openMainActivity = new Intent("com.askselva.simple.MENU");
                startActivity(openMainActivity);
            }
        }   
    };
    th.start();  
}

@Override
protected void onPause() {
    super.onPause();
    finish();
    ourSong.release();
    }
}
于 2013-09-17T10:14:15.700 回答
0

这可能会帮助你...

在 onCreate 方法中

Thread currentThread = new Thread(this);
currentThread.start();

创建后

public void run() {
    try {
        Thread.sleep(4000);
        threadHandler.sendEmptyMessage(0);
    } catch (InterruptedException e) {
        //don't forget to deal with the Exception !!!!!
    }
}

private Handler threadHandler = new Handler() {
     public void handleMessage(android.os.Message msg) {      
        Intent in = new Intent(getApplicationContext(),****.class);
        startActivity(in);
    }
};  
于 2013-09-17T10:16:50.610 回答