How can I end an action from a SurfaceView class or nested stream

Im writing an application (game) where I would like to end the game when the user leaves the game. My game is loosely based on the lunarlander, so I find it easier to ask for help using lunarlander as an example, as many are familiar with it.

When the user fails in the lunarlander game, I want to automatically complete the action (because my application uses more than one action). I know that I can use the finish () method inside the activity class, but I cannot use this method inside the surfaceview class or its nested stream. What can I do from this class, which can be used to complete an action or create a trigger for an activity class?

Or is there a completely different way that I should approach this?

Thank.

+3
source share
1 answer

Just a thought, but you can call to end parental activity. getParent().finish();

Or directly access the current context, i.e. ((Activity) context).finish();

+3
source

Source: https://habr.com/ru/post/1770522/


All Articles