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

  • Home
  • SEARCH
  • 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 8495107
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T23:28:43+00:00 2026-06-10T23:28:43+00:00

I read Hello Android book and i dont understan the following code. I dont

  • 0

I read Hello Android book and i dont understan the following code.
I dont know, what to do getIntExtra() and putExtra() int this code.

 private void startGame(int i) {
     Log.d(TAG, "clicked on " + i);
     Intent intent = new Intent(Sudoku.this, Game.class);
     intent.putExtra(Game.KEY_DIFFICULTY, i);
     startActivity(intent);
 }

Game.java

public class Game extends Activity {
    private static final String TAG = "Sudoku" ;
    public static final String KEY_DIFFICULTY ="org.example.sudoku.difficulty" ;
    public static final int DIFFICULTY_EASY = 0;
    public static final int DIFFICULTY_MEDIUM = 1;
    public static final int DIFFICULTY_HARD = 2;
    private int puzzle[] = new int[9 * 9];
    private PuzzleView puzzleView;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        Log.d(TAG, "onCreate" );
        int diff = getIntent().getIntExtra(KEY_DIFFICULTY,DIFFICULTY_EASY);
        puzzle = getPuzzle(diff);
        calculateUsedTiles();
        puzzleView = new PuzzleView(this);
        setContentView(puzzleView);
        puzzleView.requestFocus();
    }
    // ...
}

The problem I have is that you are setting a local integer (‘diff’) within the Game class. with a default value of zero (easy) and then immediately passing it into the getPuzzle method …. how does the user input value ( the real value all being well) ever find it’s way into the getPuzzle method?

  • 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-06-10T23:28:45+00:00Added an answer on June 10, 2026 at 11:28 pm

    This code:

     Intent intent = new Intent(Sudoku.this, Game.class); 
     intent.putExtra(Game.KEY_DIFFICULTY, i); 
     startActivity(intent); 
    

    creates an intent which, when executed with startActivity, does two things:

    • It starts a new activity of class Game (specified by the parameter Game.class) and
    • it passes i (= the user input) into the activity, tagged with the string content of KEY_DIFFICULTY.

    In the activity, this line:

     int diff = getIntent().getIntExtra(KEY_DIFFICULTY, DIFFICULTY_EASY); 
    

    reads the value that was set for KEY_DIFFICULTY in the intent used to start the activity. Hence, diff now contains the user-selected value (or DIFFICULTY_EASY, if the activity is started through a different intent which did not set KEY_DIFFICULTY).

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

Sidebar

Related Questions

I have to read a file called hello.txt using the following code on java/eclipse/android:
I'm reading the book 'Hello, Android'. In the Sudoku example, it uses a options
Hello I've already read quite a bit about the CheckBox/ListView problems in Android. So
I'm trying to use Android Maps, following the instructions in Hello MapView . I've
Hello i am new to Android, I'm getting this problem even after having the
I want to read a file (hello.in) and to write it to another file
Hello I want to read output of command which gives progress bar like output
Hello I have a problem wherein I have to read a huge csv file.
Hello is have a question for a school assignment i need to : Read
Hello here is my script: ARGV.each do |input_filename| doc = Nokogiri::HTML(File.read(input_filename)) title, body =

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.