-4

代码:

package com.guess.guessthefone;

import android.media.MediaPlayer;

import android.os.Bundle;

import android.app.Activity;

import android.content.Intent;

import android.view.Menu;

public class MainActivity extends Activity {

MediaPlayer logoMusic;

    @Override

    public void onCreate(Bundle savedInstanceState) {

        super.onCreate(savedInstanceState);

        setContentView(R.layout.splash);

        MediaPlayer logoMusic = MediaPlayer.create(MainActivity.this, R.raw.splash_sound);
        logoMusic.start();

        Thread logoTimer = new Thread(){

            public void run(){


                try{
                    sleep(2000);
                Intent MenuIntent =  new Intent("com.guess.guessthefone.SPLASH");
                    startActivity(MenuIntent);



                } catch (InterruptedException e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                }

                finally{


                    finish();

                }
            }

        };
        logoTimer.start();
    }




    @Override

    public boolean onCreateOptionsMenu(Menu menu) {

        getMenuInflater().inflate(R.menu.activity_main, menu);

        return true;
    }

}

我的 LogCat 输出是:

08-24 16:40:33.558: D/dalvikvm(322): GC_EXTERNAL_ALLOC freed 48K, 53% free 2551K/5379K, external 1625K/2137K, paused 74ms

08-24 16:40:36.048: W/dalvikvm(322): threadid=9: thread exiting with uncaught exception (group=0x40015560)

08-24 16:40:36.057: E/AndroidRuntime(322): FATAL EXCEPTION: Thread-10

08-24 16:40:36.057: E/AndroidRuntime(322): android.content.ActivityNotFoundException: No Activity found to handle Intent { act=com.guess.guessthefone.Menu }

08-24 16:40:36.057: E/AndroidRuntime(322):  at android.app.Instrumentation.checkStartActivityResult(Instrumentation.java:1409)

08-24 16:40:36.057: E/AndroidRuntime(322):  at android.app.Instrumentation.execStartActivity(Instrumentation.java:1379)

08-24 16:40:36.057: E/AndroidRuntime(322):  at android.app.Activity.startActivityForResult(Activity.java:2827)

08-24 16:40:36.057: E/AndroidRuntime(322):  at android.app.Activity.startActivity(Activity.java:2933)

08-24 16:40:36.057: E/AndroidRuntime(322):  at com.guess.guessthefone.MainActivity$2.run(MainActivity.java:29)
4

2 回答 2

1

此外,播放器应在播放视频之前做好准备。你应该接触preparedlistener

final MediaPlayer logoMusic = MediaPlayer.create(MainActivity.this, R.raw.splash_sound);
//set your dataSource here
logoMusic .setOnPreparedListener(new MediaPlayer.OnPreparedListener() {
    @Override
    public void onPrepared(MediaPlayer mp) {
    logoMusic.start();
    }
});
于 2012-08-24T11:02:34.303 回答
1

改变这个。

  Intent MenuIntent =  new Intent(MainActivity.this,SPLASH.class);
  startActivity(MenuIntent);

并在 android 清单文件中声明了您的SPLASH Activity。

<activity
        android:name=".SPLASH"/>
于 2012-08-24T10:50:03.520 回答