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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T21:26:09+00:00 2026-06-17T21:26:09+00:00

So, I am currently trying to edit the Snake game that android’s api provides.

  • 0

So, I am currently trying to edit the Snake game that android’s api provides. I am trying to make it so that after pressing menu->settings->resume, it would resume the game. However, instead of going all the way to resume, after I press settings, it quits and resumes from there. I am using Intents to resume the program.

public boolean onOptionsSelected(MenuItem menu){
    switch(menu.getItemId()){
        case R.id.settings:
        Intent prefActivity = new Intent(this,MyPreferences.class);
        startActivityForResult(prefActivity, KEY_RESUME_RESULT);
        return true;
}

public void onActivityResult(int requestCode, int resultCode, Intent data){
    switch(requestCode){
    case KEY_RESUME_RESULT:
        if(resultCode==RESULT_OK){
            if(mSnakeView.getMode() == SnakeView.PAUSE)
                this.mSnakeView.setMode(SnakeView.RUNNING);
        }
    }
}

This is in MyPreferences.class

public void onCreate(Bundle savedInstanceState){
        super.onCreate(savedInstanceState);
        addPreferencesFromResource(R.xml.snake_preferences);
        resume = (Preference)findPreference(getString(R.string.key_resume));
        onPreferenceTreeClick(this.getPreferenceScreen(),resume);
    }

@Override
public boolean onPreferenceTreeClick(PreferenceScreen preferencescreen,Preference preference){
        super.onPreferenceTreeClick(preferencescreen,preference);
        Intent intent = new Intent();
        if(preference == resume){
            setResult(Activity.RESULT_OK,intent);
            finish();
        }
        return true;
    }
  • 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-17T21:26:11+00:00Added an answer on June 17, 2026 at 9:26 pm

    You’re explicity calling the method that resumes the game inside onCreate(), which is probably why the game is resuming as soon as you launch settings. I’d suggest not using the method and instead setting up a click listener for your preference:

    public void onCreate(Bundle savedInstanceState){
      super.onCreate(savedInstanceState);
      addPreferencesFromResource(R.xml.snake_preferences);
      resume = (Preference)findPreference(getString(R.string.key_resume));
      resume.setOnPreferenceClickListener (new Preference.OnPreferenceClickListener()
                                             {
        @Override
        public void onPreferenceClick(Preference preference)
        {
          setResult(Activity.RESULT_OK,intent);
          finish();
        }
      });
    }
    

    Also, based on your code onOptionsSelected() doesn’t explicitly pause the game (however the UI should be paused considering that onPause() will be called), you might want to look into that.

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

Sidebar

Related Questions

I'm currently trying to edit a project, that already uses OpenCL.dll, to make it
Currently trying at add ajax to a site, after much reading I discovered that
I am currently trying to write some code that will accept some FTP details,
I am currently trying to access the data that was just inserted using: if($this->User->save($this->data))
I am currently trying to edit my db named boh. The current table files
Currently I'm trying to edit a hidden form with the command: jQuery(document).ready(function(){ jQuery(#test).val(hi); });
I'm trying to make a tag that behaves differently based on the route, but
I am currently trying to make a Writing program. I would like the functionality
I'm currently trying to edit a website for a client which uses Adobe Contribute
I am currently trying to keep an alert dialog with edit text showing on

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.