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 5954643
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T17:59:59+00:00 2026-05-22T17:59:59+00:00

I am building a game, that is step based, so I need to be

  • 0

I am building a game, that is step based, so I need to be able to create forward and back button.

Each step has an Id and the info for it is taken from and SQLite database. I am going to be saving maxLevel, the maximum reached step, as well as currentStep, the current step, in the shared preferences. Now I was wondering how do I start a new action that would take someone to the next/previous step, without clogging up the memory too much. I know I can start a new action and pass it data something like this:

final Context mContext=this;
SharedPreferences settings = getSharedPreferences(PREFS_NAME, 0);
                        SharedPreferences.Editor editor = settings.edit();
                        editor.putInt("count", 2);
                        editor.commit();
                        Intent myIntent = new Intent(mContext, PlayGame.class);
                        mContext.startActivity(myIntent);

Now my main worry here is the memory usage. If I go forward 2 times using this, then back 2 times and then forward 2 times again, won’t it create 6 instances of the activity? That could be a massive memory hog.

So the question here is:

How do I implement a forward/back system with 1 activity, that is relaunched and retrieves data from a database?

For more background info: The activity is a TabHost, which has 4 tabs, and each of these tabs has an activity inside it. Each activity retrieves the data it needs from the database. Therefore my concern about the memory usage.

Edit:

I seem to have found a solution. I am calling the finish() function before I start the new activity. I do believe, that this should help avoid any leaks. am I right in thinking 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-22T18:00:00+00:00Added an answer on May 22, 2026 at 6:00 pm

    Just a thought

    How about running a back ground thread which will update your UI, Such as AsynTask. back and forward method will trigger background thread which will update your UI and can update data from SQL as well, By this you don’t have to change activity

    Helpful Links,

    http://developer.android.com/resources/articles/painless-threading.html

    http://topandroid.net/threads-handlers-asynctask

    Happy Coding!

    After your edition,

    If your second activity has different data structure than this is a good idea to finish() as you are going to create new object anyway. But if data structure is same than probably using same objects and update their value will be more efficient.

    One more edition, After updating your variables from background thread you may have to call set methods on your views for your UI to show a recent change. This is logical but just wanted to share it 🙂

    Enjoy!

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

Sidebar

Related Questions

I'm diving into iOS development and am building a game that has multiple game
I'm building a game in as3 that has balls moving and bouncing off the
I'm creating a building game in JavaScript and PHP that involves a grid. Each
I'm building a BattleShip game for WP7 that has board with 250 cells. I
I'm building a JavaScript based poker game that get some updates from a server
I'm building simple game and I need to set game speed for each level.
I am planning to create a Flash AS3 game that is like SimCity. Or
I'm taking my first steps in C#. I'm building a turned based cards game
I'd like to build a turn-based, multiplayer iPhone game that will require a game
I'm building a game that got some moving things all the time, so I'm

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.