美好的一天,我一直在为我的android程序做一些编码,我尝试用此代码播放音乐,在这里android,最低的版本是2.2而最高的是4.2.2,也使用eclipse来做到这一点,并且设备仿真器是nexus

在全局范围内

    MediaPlayer Sound;

这是在setContentView下
    Sound = MediaPlayer.create(Splash.this, R.raw.kalimba);
    Sound.start();

这就是整个代码
import android.app.Activity;
import android.content.Intent;
import android.media.MediaPlayer;
import android.os.Bundle;
public class Splash extends Activity {
MediaPlayer Sound;
@Override
protected void onCreate(Bundle savedInstanceState) {
    // TODO Auto-generated method stub
    super.onCreate(savedInstanceState);
    setContentView(R.layout.splash);
    Sound = MediaPlayer.create(Splash.this, R.raw.kalimba);
    Sound.start();
    Thread timer = new Thread(){
        public void run(){
            try{
                sleep(5000);
            } catch(InterruptedException e){
                e.printStackTrace();
            }finally{
                Intent openStartingPoints = new              Intent("com.mysampleapp.simplybel.MainActivity");
                startActivity(openStartingPoints);
            }//this is the end for the finally
        }//this is the end for the run
    };//this is the end for the thread timer
    timer.start();

}//this is the end for the oncreate

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


}

有人可以帮我吗?

最佳答案

这可能是出于您的意图。您到底要用这个意图做什么?

明确意图的正确语法应类似于此intent tutorial。例如,Intent openStartingPoints=new Intent(context,MainActivity.class);和context必须像Context context;这样的全局变量声明在线程之外,并在onCreate()内使用context=this;实例化它,以将其设置为当前 Activity 的上下文。

另一个建议是,您应始终以驼峰形式命名变量名称,因此首字母应小写。

让我知道这是否有任何变化。除此之外,我看不到提供的代码有任何问题。

07-24 18:56
查看更多