如何从 SurfaceView 类或嵌套线程内部结束活动
我正在编写一个应用程序(游戏),我想在用户游戏失败时结束游戏活动。我的游戏大致基于lunarlander,因此我认为以lunarlander 为例寻求帮助可能会更容易,因为很多人都熟悉它。
当用户在lunarlander游戏失败时,我想自动结束该活动(因为我的应用程序使用多个活动)。我知道我可以在 Activity 类中使用 finish() 方法,但我不能在 SurfaceView 类或其嵌套线程中使用该方法。我可以在此类中执行哪些操作来结束活动或创建返回活动类的触发器?
或者,我应该采取完全不同的方式来解决这个问题吗?
谢谢。
I’m writing an application (game) where I would like to end the game activity when the user fails the game. My game is loosely based off lunarlander, so I figure it may be easier to ask for help using lunarlander as an example, since a lot of folks are familiar with it.
When the user fails the lunarlander game, I want to automatically end the activity (because my app uses more than one activity). I know that I can use the finish() method inside the activity class, but I can’t use that method inside the surfaceview class or its nested thread. What can I do from inside this class that can be used to end the activity or create a trigger back to the activity class?
Or, is there an entirely different way I should approach this?
Thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
只是一个想法,但您可以在父活动上调用 finish .. 例如
getParent().finish();
或者直接访问当前上下文,即
((Activity) context).finish() ;
Just a thought but can you call finish on the parent activity.. e.g.
getParent().finish();
Or directly access the current context i.e.
((Activity) context).finish();