我正在創建一個應用程序,它會在開始時加載MediaPlayer,然後幾秒鐘後,這個類將被銷燬並移動到另一個類。問題是我試圖阻止MediaPlayer,只要第一個類被破壞,但它會強制關閉我。這是代碼。嘗試使用release()時Android強制關閉;停止MediaPlayer
public class HelloWorldActivity extends Activity {
MediaPlayer mp;
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.splash);
final MediaPlayer mp = MediaPlayer.create(this, R.raw.otj);
mp.start();
Thread LogoTimer = new Thread() {
public void run() {
try {
int LogoTimer = 0;
while(LogoTimer < 5000) {
sleep(100);
LogoTimer = LogoTimer + 100;
}
startActivity(new Intent("com.example.HelloWorld.CLEARSCREEN"));
}
catch (InterruptedException e) {
e.printStackTrace();
}
finally {
finish();
}
}
};
LogoTimer.start();
}
protected void onDestroy() {
super.onDestroy();
mp.release();
}
解決了!謝謝! – regi