我的應用程序有一個mainactivity ...安卓:在的onResume不MainActivity叫
public class MainActivity extends Activity {
GameView gameView;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
gameView = new GameView(this);
requestWindowFeature(Window.FEATURE_NO_TITLE);
setContentView(gameView);
this.getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
WindowManager.LayoutParams.FLAG_FULLSCREEN);
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
// we dont know yet tho
return true;
}
@Override
protected void onPause() {
super.onPause();
gameView.gameLoopThread.onPause();
}
@Override
protected void onResume() {
super.onResume();
gameView.gameLoopThread.onResume();
}
}
和gameLoopThread是
public class GameLoopThread extends Thread {
private GameView view;
private boolean isRunning = false;
static final long FPS = 32;
private boolean mPaused = false;
private Object mPauseLock;
public GameLoopThread(GameView view) {
this.view = view;
mPauseLock = new Object();
}
public void setIsRunning(boolean isRunning) {
this.isRunning = isRunning;
}
@SuppressLint("WrongCall")
@Override
public void run() {
long ticksPS = 1000/FPS;
long startTime;
long sleepTime;
while (isRunning) {
Canvas c = null;
startTime = System.currentTimeMillis();
try {
c = view.getHolder().lockCanvas();
synchronized (view.getHolder()) {
view.onDraw(c);
}
} finally {
if (c != null) {
view.getHolder().unlockCanvasAndPost(c);
}
}
sleepTime = ticksPS - (System.currentTimeMillis() - startTime);
try {
if (sleepTime > 0)
sleep(sleepTime);
else
sleep(10);
} catch (Exception e) {
}
synchronized (mPauseLock) {
while (mPaused) {
try {
mPauseLock.wait();
} catch (InterruptedException e) {
e.printStackTrace();
}
}
}
}
}
public void onPause() {
synchronized (mPauseLock) {
mPaused = true;
}
}
public void onResume() {
synchronized (mPauseLock) {
mPaused = false;
mPauseLock.notifyAll();
}
}
}
反正onResume()
在MainActivity沒有得到稱爲:我通過在那裏放置一個斷點來確定這一點。所以當我退出應用程序時遊戲暫停,但是當我回到應用程序時,它僅僅是遊戲的暫停屏幕,並且不會再次恢復:當我重新輸入應用程序時,我希望它恢復(使用最近的應用程序屏幕)。 這裏是logcat,以防有什麼意義。
12-22 21:39:09.382: I/System.out(10992): Sending WAIT chunk
12-22 21:39:09.402: I/dalvikvm(10992): Debugger is active
12-22 21:39:09.582: I/System.out(10992): Debugger has connected
12-22 21:39:09.592: I/System.out(10992): waiting for debugger to settle...
12-22 21:39:09.792: I/System.out(10992): waiting for debugger to settle...
12-22 21:39:09.985: I/System.out(10992): waiting for debugger to settle...
12-22 21:39:10.185: I/System.out(10992): waiting for debugger to settle...
12-22 21:39:10.392: I/System.out(10992): waiting for debugger to settle...
12-22 21:39:10.592: I/System.out(10992): waiting for debugger to settle...
12-22 21:39:10.795: I/System.out(10992): waiting for debugger to settle...
12-22 21:39:10.994: I/System.out(10992): debugger has settled (1313)
12-22 21:39:12.343: D/dalvikvm(10992): threadid=1: still suspended after undo (sc=1 dc=1)
12-22 21:42:21.922: W/ActivityThread(11454): Application com.dotdodge is waiting for the debugger on port 8100...
一些logcat的請 –
@chintankhetiya什麼,除了調試器被激活,調試器連接,等待debbuger定居,和調試器解決 –
@GeoreShg嘗試創建的實例'恢復方法中的'GameView'。在你的onResume方法中寫下這行'gameView = new GameView(this);'然後檢查。 – GrIsHu