我正在開發一款適用於Android的應用程序,我希望它在您按主頁按鈕(onPause)時暫停音樂。這很好,但是當我嘗試再次啓動遊戲時,onResume,onRestart,onStart,onRestoreInstanceState和onCreate永遠不會被調用,它告訴我應用程序沒有響應。 LogCat中沒有顯示異常...所以我不知道發生了什麼。有沒有人有任何建議,爲什麼這可能是這種情況?Android onResume不叫
CNC中 我做在logcat中得到這個錯誤,當應用程序暫停:
04-16 20:09:32.659:ERROR/ActivityManager(66):原因:廣播意向{ACT =機器人.intent.action.CLOSE_SYSTEM_DIALOGS CMP = com.android.settings/.widget.SettingsAppWidgetProvider(具有額外)}
我的onPause()的代碼:
public void onPause() {
super.onPause();
panel.mediaPlayer.pause();
panel.thread.running=false;
}
主應用程序線程:
public void run() {
running = true;
while(running) {
//new Canvas.
Canvas c = null;
//Update information
update();
//Draw everything to screen
try {
//Gets the canvas from the surfaceHolder.
c = surfaceHolder.lockCanvas(null);
synchronized(surfaceHolder) {
//draw to the canvas
doDraw(c);
try {
Thread.sleep(gameSpeed);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
} finally {
if (c != null) {
surfaceHolder.unlockCanvasAndPost(c);
}
}
}
MEDIAPLAYER:
mediaPlayer = new MediaPlayer();
sublime = context.getResources().openRawResourceFd(R.raw.sublime);
try {
mediaPlayer.setLooping(true);
mediaPlayer.setDataSource(sublime.getFileDescriptor(), sublime.getStartOffset(), sublime.getLength());
mediaPlayer.prepare();
} catch (IllegalArgumentException e1) {
} catch (IllegalStateException e1) {
} catch (IOException e1) {
}
mediaPlayer.start();
發佈您的onPause()代碼以及與設置它所操作的對象有關的任何其他內容。 – Squonk 2011-04-16 20:24:58