缺陷在月球着陆的例子(IllegalThreadStateException)月球、缺陷、例子、IllegalThreadStateException

2023-09-12 22:23:59 作者:我为你哭你却在为她在笑﹌

我一直在玩与周围的月球着陆器的例子,遇到了一个问题,而试图实现一个约屏幕。我换了菜单项(在onCreateOptionsMenu)之一的关于选项。如果选择此选项,新的活动开始,并显示有关画面。

I've been playing around with the lunar lander example and have run into a problem while trying to implement an about screen. I changed one of the menu items (in onCreateOptionsMenu) to an "about" option. When this option is selected, a new Activity starts and displays an about screen.

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    switch (item.getItemId()) {
        case MENU_ABOUT:
            startActivity(new Intent(this, About.class));
            return true;
            //Other cases
    }
    return false;
}

这完美的作品和焦点移动到一个新的活动。然而,当我preSS回手机上,回到游戏,程序崩溃。我得到这个错误:

This works perfectly and a the focus moves to a new Activity. However, when I press back on the phone to get back to the game, the program crashes. I get this error:

Thread [<3> main] (Suspended (exception IllegalThreadStateException))   
LunarView(SurfaceView).updateWindow(boolean) line: 465  
LunarView(SurfaceView).onWindowVisibilityChanged(int) line: 189 
LunarView(View).dispatchWindowVisibilityChanged(int) line: 3782 
FrameLayout(ViewGroup).dispatchWindowVisibilityChanged(int) line: 704   
FrameLayout(ViewGroup).dispatchWindowVisibilityChanged(int) line: 704   
PhoneWindow$DecorView(ViewGroup).dispatchWindowVisibilityChanged(int) line: 704 
ViewRoot.performTraversals() line: 710  
ViewRoot.handleMessage(Message) line: 1650  
ViewRoot(Handler).dispatchMessage(Message) line: 99 
Looper.loop() line: 123 
ActivityThread.main(String[]) line: 4595    
Method.invokeNative(Object, Object[], Class, Class[], Class, int, boolean) line: not available [native method]  
Method.invoke(Object, Object...) line: 521  
ZygoteInit$MethodAndArgsCaller.run() line: 860  
ZygoteInit.main(String[]) line: 618 
NativeStart.main(String[]) line: not available [native method]  

谁能帮我找出什么回事?我遇到了同样的问题,任何时候我尝试回来从其他的东西(无论其来自preferences活动,帮助活动,或从主屏幕)的游戏画面。谢谢

Can anyone help me figure out whats going on? I run into the same problem anytime I try to come back to the game screen from something else (whether its from a preferences Activity, a help Activity, or from the home screen). Thanks

推荐答案

这是小说给了我带到了答案的链接。这个问题是不是在我的code,这是由于在月球着陆的例子缺陷(它不处理它的线程正常)。

The link that fiction gave led me to the answer. The problem wasn't in my code, it was due to a flaw in the Lunar Lander example (it doesn't handle its thread properly).

为寻找不使用月球着陆器的有缺陷的框架,一个稳定的游戏循环,我发现这个例子很好地工作:的 http://blorb.tumblr.com/post/236799414/simple-java-android-game-loop

For anyone looking for a stable game loop that doesn't use Lunar Lander's flawed framework, I found this example to work very well: http://blorb.tumblr.com/post/236799414/simple-java-android-game-loop

感谢您的帮助