Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6868633
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T03:27:30+00:00 2026-05-27T03:27:30+00:00

I now have a MainMenu activity, with a XML file for it’s layout. By

  • 0

I now have a MainMenu activity, with a XML file for it’s layout. By pressing a button an Intent brings the user to the activity of the game, which has a GLSurfaceView.

I use my ‘Game’ class to manage all game objects, lives, and resets etc… When lives reaches 0 I want to call onGameOver(), which should return you to the MainMenu activity. How do I accomplish this?

I tried having a static call to my Activity Class, to either call:

moveTaskToBack(true);
startActivity(intentToMainMenu);

I have just no Idea how I can return to the mainmenu. Also I believe I should destroy the activity of the game, since the OpenGL context will be lost if I switch activities. So how do I do this?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T03:27:31+00:00Added an answer on May 27, 2026 at 3:27 am

    You could do like Frank posted, but in your particular case you probably don’t want to finish of the game activity(the player will probably play again). No context will be lost. If you finish of you game activity, starting a new one every time will be slow. Because of this, it’s better to start activities like this:

    Intent i = new Intent(getApplicationContext(), YourActivity.class);
    i.setFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT);
    startActivity(i);
    

    The reorder to front flag makes sure you don’t have multiple instances of the same activity because it doesn’t start a new activity if one already exists. So when the player runs out of lives you simple start MainMenu like the example above.

    PS: You can’t finish off activities statically.

    In light of your comment, here’s an update:

    Although there probably are better solutions, here’s a solution that I use: Since you are creating a game you probably have a separate thread that draws stuff and checks whether the game has finished. Register a handler for the rendering thread that exists in the UI thread in your Activity. Then you will be able to post a message to the Handler in the Activity class when the game should end. On the receiving end, you just do the code posted in my answer since you won’t be in a static method.

    If you are unfamiliar with handlers: http://saigeethamn.blogspot.com/2010/04/threads-and-handlers-android-developer.html

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I now have a running Java program which only lacks of the final step,that
I have a NSDocument based application, which allows the user to send messages, after
I have a menu defined via an XML resource. Now dynamically I add a
Hi there when my game reaches it's Game Over Scene i have a button
I now have it set up so that when people go to a thank
Modern ATL/MFC applications now have access to a new shared pointer class called CAutoPtr,
in /usr/local i now have two mysql folders: mysql-5.1.34-osx10.5-x86 mysql-5.1.37-osx10.5-x86_64 is it possible to
The javascript code I now have can toggle a single row of data. Whether
Following on from this question I now have code that can attach to a
With help from you guys I now have a script that works like a

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.