强制关闭一次又一次

时间:2012-08-24 10:43:43

标签: android

代码:

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)

2 个答案:

答案 0 :(得分:1)

改变这一点。

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

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

<activity
        android:name=".SPLASH"/>

答案 1 :(得分:1)

此外,播放器应该在播放视频之前做好准备。你应该准备一个touchlistener

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