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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T16:01:42+00:00 2026-06-07T16:01:42+00:00

I have an class Voice , which extends Activity , and contains a counter.

  • 0

I have an class Voice, which extends Activity, and contains a counter. When the user answers correctly, the counter adds one via counter++;

public class Voice  extends Activity implements OnClickListener{
    ListView lv;
    static final int check = 111;
    int counter_score;
    TextView txView;
    MediaPlayer ourSong;
    ImageView display;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.letter_a);
        initialize();
    }

    private void initialize() {
        lv = (ListView)findViewById(R.id.lvVoiceReturn);
        Button b = (Button)findViewById(R.id.imageButtonSelector);
        txView = (TextView)findViewById(R.id.counter);
        b.setOnClickListener(this);
        counter_score=0;
    }

This score, is bundled and passed on to the next activity “What” within a string “your score is 1”.

protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    if (requestCode == check && resultCode == RESULT_OK) {
        ArrayList<String> results = data.getStringArrayListExtra(RecognizerIntent.EXTRA_RESULTS);
        lv.setAdapter( new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, results));

        if(results.contains("hey") || results.contains("a") || results.contains("ay")) {
            //toast referenced to xml the after 400ms
            counter_score++;
            txView.setText("Your Score is" + " " + counter_score);

            AlertDialog dialogBuilder = new AlertDialog.Builder(this).create();
            dialogBuilder.setTitle("AWSOME");
            dialogBuilder.setMessage("¡Your current score is" + counter_score);
            dialogBuilder.setIcon(R.drawable.ic_mark);
            dialogBuilder.show();

            ourSong = MediaPlayer.create(Voice.this, R.raw.rightsound2);
            ourSong.start();
            Thread timer = new Thread() {
                public void run(){
                try {
                    sleep(2500);
                }catch (InterruptedException e){
                    e.printStackTrace();
                } finally {
                    String score = txView.getText().toString();
                    Bundle keeper = new Bundle();
                    keeper.putString("key", score);
                    Intent putScore = new Intent(Voice.this, What.class);
                    putScore.putExtras(keeper);
                    startActivity(putScore);
                }
            }
        };

        timer.start();
    }
}

The next Activity, What, gets this Bundle and displays it fine using setText(gotScore)

public class What  extends Activity implements OnClickListener {
    ListView lv;
    static final int check = 111;
    private int counter_score;
    TextView txView;
    MediaPlayer ourSong;
    ImageView display;
    String gotScore;

    String classes[] = {"What", "Pagina", "What", "example3", "example4", "example5", 
                        "example6"};

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.letter_b);
        initialize();
        Bundle gotKeeper = getIntent().getExtras();
        gotScore = gotKeeper.getString("key");
        txView.setText(gotScore);
    }

    private void initialize() {
        // TODO Auto-generated method stub
        lv = (ListView)findViewById(R.id.lvVoiceReturn);
        Button b = (Button)findViewById(R.id.imageButtonSelector);
        txView = (TextView)findViewById(R.id.counter);
        b.setOnClickListener(this);

..this is when things go bad 🙁

On What I have another question tied to a counter as well. When the user answers correctly the counter adds one via counter++; and it does. However, it changes the txview string to “your score is 1”. I can’t get it to add 1 to the counter result passed from the previous activity within the string, so that the counter on What reads “your score is 2”. This gets passes to the next activity in Bundle keeper, which holds the aggregate score.

I’ve read a few tutorials on passing an int verses a string, but some of the code they use like getInt is not recognized. I’m stumped.

  • 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-07T16:01:47+00:00Added an answer on June 7, 2026 at 4:01 pm

    What you’re bundling and passing to the What activity is not the counter but the string “Your score is 1”. If you want to increment that number in the next activity then you should be sending just the integer value and constructing whatever string you need there instead.

    I ve read a few tuts on passing an int vs a string..but some of the code they use like getInt is not recognized..anywho Im stumped..

    I’m not too sure I know what you mean by getInt() is not recognized. In any case, make things easier for yourself when passing counter from one activity to another. If it is an int and you plan on manipulating like an int in the receiving activity then add it to the bundle as an int. For example:

        Bundle keeper = new Bundle();
        keeper.putInt("key", counter_score);
    

    And retrieve it from the bundle with:

        Bundle gotKeeper = getIntent().getExtras();
        int score = gotKeeper.getInt("key");
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have class like this below shown. which contains the shopping items where the
I have a class which extends JFrame and forms the GUI of my program.
I have Class and Student objects. Both have collection of another as property. Which
I have class LegacyClass which inherits OldBaseClass. I'm considering a change to introduce a
I have class with back reference: public class Employee : Entity { private string
I have class with collection as below public class MyClass:IXmlSerializable { int vesrion; private
I have class Meat extends Food { $var = Food::foodFunction… } I need to
We have class lua. In lua class there is a method registerFunc() which is
I have class that looks like this: class A { public: class variables_map vm
HI all, I am having a thread Checker (extends thread class) which keeps 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.