Android crash when app is closed and reopened

前端 未结 3 1604
渐次进展
渐次进展 2020-11-28 07:47

I have a really simple android app that just displays a blank white screen. When I close the app by pressing the HOME button, then try to open the app again, it crashes and

3条回答
  •  南方客
    南方客 (楼主)
    2020-11-28 08:17

    The solution below was tested. The code checks thread state, and if terminated creates a new one. No crashes, the only problem I can see is the game state is not saved so basically getting back from a HOME key press, starts the game again. p.s. remember to pass through the context from Lunarview view and set to mContextLunarView. Hope this helps. These forums are awesome. Keep it up.

    public void surfaceCreated(SurfaceHolder holder) {
        // start the thread here so that we don't busy-wait in run()
        // waiting for the surface to be created    
    
        if(thread.getState() == Thread.State.TERMINATED) {
            //LunarView Thread state TERMINATED..make new...under CheckCreateThread
    
            thread = new LunarThread(holder, mContextLunarView, new Handler() {
                @Override
                public void handleMessage(Message m) {
                    mStatusText.setVisibility(m.getData().getInt("viz"));
                    mStatusText.setText(m.getData().getString("text"));
                }
            });     
        }   
    
        thread.setRunning(true);
        thread.start();
    }
    

提交回复
热议问题