I am writing my first android game. It is working fine in almost every respect, but when the screen timeout kicks in and I press the button to get back to the game, I find the image of the game state frozen. It appears the main thread is still alive - I can tell this because I have a set of sounds that occur when I drag certain objects around the screen, and the sounds still behave as if everything was working (except that I see nothing other than the frozen screen). If I then select a menu to show the "high scores" activity and then exit back to the game, I find all is well and can continue with all the graphics working properly.
我不敢肯定,为了诊断这一问题,需要列入我法典的哪些部分,但这里是我的想法——如果要求,我会增加:
http://www.un.org。 根据Brigham的建议,我对法典做了两.,但症状相同。
http://www.un.org。 我已经注意到,如果我点一个纽子来煽动“高分点”活动,那么就会有人叫.。 但是,当场外cks(www.em>not)时。
http://www.un.org。 在没有解决办法的情况下,对该问题有很多看法——我认为问题必须十分trick弄——或者也许没有在《规则》中披露。 关于我如何能够
http://www.un.org。 我现在将整个(简化)项目简单地放在桌面上,并将其放在网上:。 - 关键代码都简单明了。 java
MicksPanelThing mpt = null;
public MicksThreadThing micks_thread_thing = null;
@Override
protected void onPause() // pair with onResume
{
super.onPause();
allow_draw.set(false);
micks_thread_thing.setRunning(false);
save_state();
}
@Override
protected void onResume() // pair with onPause
{
super.onResume();
get_state();
mpt.get_a_new_thread_all_over_again();
micks_thread_thing.setRunning(true);
allow_draw.set(true);
}
////////////////////////////////////////////////////////////////////////////
public class MicksPanelThing extends SurfaceView implements SurfaceHolder.Callback
{
public MicksPanelThing(Context context)
{
super(context);
}
public void get_a_new_thread_all_over_again()
{
getHolder().addCallback(this);
micks_thread_thing = new MicksThreadThing(getHolder(), this);
setFocusable(true);
}
@Override
public boolean onTouchEvent(MotionEvent event)
{
synchronized (micks_thread_thing.getSurfaceHolder())
{
if (event.getAction() == MotionEvent.ACTION_DOWN)
{
// blah
}
if (event.getAction() == MotionEvent.ACTION_MOVE && selected_node != -1)
{
// blah
}
if (event.getAction() == MotionEvent.ACTION_UP)
{
// blah
}
return true;
}
}
@Override
public void onDraw(Canvas canvas)
{
canvas_width = canvas.getWidth();
canvas_height = canvas.getHeight();
if (allow_draw.get())
{
canvas.drawBitmap(sandy_bitmap, 0, 0, null);
// blah
}
}
public void surfaceCreated(SurfaceHolder holder)
{
micks_thread_thing.setRunning(true);
micks_thread_thing.start();
we_have_a_surface = true;
}
public void surfaceDestroyed(SurfaceHolder holder)
{
boolean retry = true;
micks_thread_thing.setRunning(false);
while (retry)
{
try
{
micks_thread_thing.join();
retry = false;
micks_thread_thing = null;
}
catch (InterruptedException e)
{
// we will try it again and again...
}
}
we_have_a_surface = false;
}
}
class MicksThreadThing extends Thread
{
private SurfaceHolder surf_holder = null;
private MicksPanelThing micks_panel_thing;
private boolean this_thread_is_currently_active = false;
public MicksThreadThing(SurfaceHolder surfaceHolder, MicksPanelThing mpt)
{
surf_holder = surfaceHolder;
micks_panel_thing = mpt;
}
public void setRunning(boolean set_run)
{
this_thread_is_currently_active = set_run;
}
public SurfaceHolder getSurfaceHolder()
{
return surf_holder;
}
@Override
public void run()
{
Canvas c;
while (this_thread_is_currently_active)
{
c = null;
try
{
c = surf_holder.lockCanvas(null);
synchronized (surf_holder)
{
micks_panel_thing.onDraw(c);
}
}
finally
{
if (c != null)
{
surf_holder.unlockCanvasAndPost(c);
}
}
}
}
}
public class Allow_draw
{
private boolean draw;
Allow_draw()
{
draw = false;
}
public void set(boolean x)
{
synchronized (this)
{
draw = x;
}
}
boolean get()
{
synchronized (this)
{
return draw;
}
}
}