2012-08-24 84 views
-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的ouptput是:

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) 
+7

LogCat說什麼? – Nikhil

+0

把媒體播放器放在一個單獨的線程中 –

+2

不要試圖拉扯你,但你應該是那些先解決這個問題的人,通過適當地描述問題,以及如何發生。 –

回答

1

改變這一點。

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

,並宣佈在Android清單文件中爲您SPLASH活動。

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

SPLASH無法解析爲類型 –

+1

我認爲您的第二個活動名稱是您要撥打的電話號碼?將SPLASH更改爲您的通話活動名稱 –

+0

是的,我嘗試過。它仍然是一樣的錯誤。另一件事是我的計時器是2秒,但是在應用程序強行關閉之後音樂會繼續播放,而在2秒後應該停止播放。 –

1

MOREOVER,播放器應該在播放視頻前準備好。你應該觸摸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(); 
    } 
}); 
相關問題