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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T11:26:34+00:00 2026-05-18T11:26:34+00:00

I’m trying to create an endgame activity for my Hangman game for android and

  • 0

I’m trying to create an endgame activity for my Hangman game for android and i’m having some trouble committing values OTHER than strings.

Here is my main activity:

package com.assignment.hangman;
import android.app.Activity;


public class HangmanActivity extends Activity {
    public static final String GAME_PREFERENCES = "Game Preferences";
    public static final String GAME_LOGIC = "Game Logic";
    public static final String GAME_LOGIC_GUESS = "Guessed letter";
    public static final String GAME_LOGIC_SCORE_STRING = "Unknow score";
    public static final boolean GAME_LOGIC_WIN_LOOSE = false;
}

I get the sharedprefs like this:

mGameSettings = getSharedPreferences("GAME_PREFERENCES", Context.MODE_PRIVATE);

And this is where something goes wrong when committing the changes to the editor:

public void finishGame() {
        //Commit different game variables so they can be used in the end game activity  
        Editor editor = mGameSettings.edit();
        editor.putString(GAME_LOGIC_SCORE_STRING, (tries + " of " + numberOfLives + " used"));
        if (tries != numberOfLives){
            editor.putBoolean("GAME_LOGIC_WIN_LOOSE", true);
        }
        editor.commit();
        // Launch end game Activity
        startActivity(new Intent(HangmanGameActivity.this, HangmanEndActivity.class));
    }

And after changing activity i refetch the values like this:

        if (mGameSettings.contains("GAME_LOGIC_WIN_LOOSE")) {
        Log.i(GAME_DEBUG, "Succes");
        boolean winLoose = mGameSettings.getBoolean("GAME_LOGIC_WIN_LOOSE", false);
        if (winLoose) {
            winLooseView.setText(R.string.you_win);
        } else {
            winLooseView.setText(R.string.you_loose);
    }
    }

But somehow only the String is being committed correctly. I guess the boolean value reverts to the default value of false.

Could someone help me shed some light on 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-18T11:26:34+00:00Added an answer on May 18, 2026 at 11:26 am

    If you only want to move the data from one activity to another I would attach it to the Intent.
    Writing it to shared memory means accessing the phone storage and that is really slow.

    You could it do in this way:

    Intent intent = new Intent(HangmanGameActivity.this, HangmanEndActivity.class);
    intent.putExtra(GAME_LOGIC_SCORE_STRING, tries + " of " + numberOfLives + " used"):
    intent.putExtra("GAME_LOGIC_WIN_LOOSE", true);  
    startActivity(intent);
    

    In the EndActivity you would do:

    Intent intent = getIntent();
    String gameString = intent.getStringExtra(GAME_LOGIC_SCORE_STRING, "default value");
    boolean win = intent.getBooleanExtra(GAME_LOGIC_WIN_LOOSE, false);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
Basically, what I'm trying to create is a page of div tags, each has
I'm trying to create an if statement in PHP that prevents a single post
I'm having trouble keeping the paragraph square between the quote marks. In firefox the
I am trying to understand how to use SyndicationItem to display feed which is
I have just tried to save a simple *.rtf file with some websites and
For some reason, after submitting a string like this Jack’s Spindle from a text
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I am trying to render a haml file in a javascript response like so:
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this

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.