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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T06:31:44+00:00 2026-06-07T06:31:44+00:00

I’m trying to make a simple sudoku but I have a problem with the

  • 0

I’m trying to make a simple sudoku but I have a problem with the Continue button. When you first start the app, the button is disabled with:

continueButton.setEnabled (false);

Thus leading the user to have to use NewGame button. That button automatically enabled the Continue button with:

continueButton.setEnabled (true);

The problem is that, closing the app, using the exit button or the back button of the phone, I lose the status of the Continue button, that when restart the app, is again disabled.

This is my code:

public class Sudoku extends Activity implements OnClickListener {
private static final String TAG = "Sudoku";
private static final String PROFILE = "stato";
boolean t = false;
SharedPreferences preferences;
int  a , b = 0, c = 0;
View continueButton;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);

// Set up click listeners for all the buttons
continueButton = findViewById(R.id.continue_button);
continueButton.setOnClickListener(this);
View newButton = findViewById(R.id.new_button);
newButton.setOnClickListener(this);
View aboutButton = findViewById(R.id.about_button);
aboutButton.setOnClickListener(this);
View exitButton = findViewById(R.id.exit_button);
exitButton.setOnClickListener(this);

t = isFirstRun();
if (t == false){
continueButton.setEnabled(false);
}else{
continueButton.setEnabled(true);
}
}


@Override
protected void onResume() {
super.onResume();
Music.play(this, R.raw.main);
}

@Override
protected void onPause() {
super.onPause();
Music.stop(this);

}

public void savePreferences(){
SharedPreferences.Editor ed = preferences.edit();
ed.putBoolean("button", true);
ed.commit();
}

public boolean isFirstRun(){
preferences = PreferenceManager.getDefaultSharedPreferences(this);   
return preferences.getBoolean("button", t);

}


//onClick method

public void onClick(View v) {
switch (v.getId()) {
case R.id.continue_button:
a = 1;
startGame(Game.DIFFICULTY_CONTINUE);
break;
// ...
case R.id.about_button:
Intent i = new Intent(this, About.class);
startActivity(i);
break;
// More buttons go here (if any) ...
case R.id.new_button://button NewGame when pressed enable continueButton
continueButton.setEnabled(true);
a = 0;

openNewGameDialog();
break;
case R.id.exit_button: //exit button


finish();


break;
}
}



@Override
public boolean onKeyDown(int keyCode, KeyEvent event)
{
if ((keyCode == KeyEvent.KEYCODE_BACK))
{       
finish();

}

return super.onKeyDown(keyCode, event);

}

@Override
public boolean onCreateOptionsMenu(Menu menu) {
super.onCreateOptionsMenu(menu);
MenuInflater inflater = getMenuInflater();
inflater.inflate(R.menu.menu, menu);
return true;
}

@Override
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
case R.id.settings:
startActivity(new Intent(this, Prefs.class));
return true;
// More items go here (if any) ...
}
return false;
}

/** Ask the user what difficulty level they want */
private void openNewGameDialog() {
new AlertDialog.Builder(this)
.setTitle(R.string.new_game_title)
.setItems(R.array.difficulty,
new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialoginterface,
int i) {
startGame(i);
}
})
.show();
}

/** Start a new game with the given difficulty level */
@SuppressLint("ParserError")
private void startGame(int i) {

Log.d(TAG, "clicked on " + i);
Intent intent = new Intent(this, Game.class);
intent.putExtra("blocca", a);
intent.putExtra(Game.KEY_DIFFICULTY, i);
startActivity(intent);
}
}
  • 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-07T06:31:45+00:00Added an answer on June 7, 2026 at 6:31 am

    Take a look at android’s Data Storage
    options. I would recommend simply saving a boolean with SharedPreferences and then check its value every time your main activity is created.

    public class MainActivity extends Activity{
    
        //Class used to retain data
        private SharedPreferences preferences;
        private boolean isFirstRun;
    
        //initialize the preferences in onCreate()
        @Override
        public void onCreate(Bundle savedInstanceState){
            super.onCreate(savedInstanceState);
            setContentView(R.layout.main);
            preferences = PreferenceManager.getDefaultSharedPreferences(this);
            isFirstRun = false;
        }
    
        //When your application gains the foreground, check to see if it is first time
        @Override
        public void onResume(){
            //if nothing has been stored, returns true since it is the first run.
            isFirstRun = preferences.getBoolean("first",true);
            if(isFirstRun)
                //disable continue button
            else
                //enable continue button
        }
    
        //Save preferences anytime your application loses the foreground
        @Override
        public void onPause(){
            SharedPreferences.Editor ed = preferences.edit();
                ed.putBoolean("first",isFirstRun);
                ed.commit();
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have just tried to save a simple *.rtf file with some websites and
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I have a French site that I want to parse, but am running into
We're building an app, our first using Rails 3, and we're having to build
Seemingly simple, but I cannot find anything relevant on the web. What is the
I am trying to loop through a bunch of documents I have to put
I'm making a simple page using Google Maps API 3. My first. One marker
I have a .ini file as follows: [playlist] numberofentries=2 File1=http://87.230.82.17:80 Title1=(#1 - 365/1400) Example
I am trying to understand how to use SyndicationItem to display feed which is
Basically, what I'm trying to create is a page of div tags, each has

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.