0

I have a hitcount that I need to be passed to another activity I know how to receive it but I'm not sure how to format it to make sure it gets passed to the other activity. The activity with the receiver is named GameActivity. This is my receiver:

public void finish(){
      Intent returnIntent = new Intent();
      returnIntent.putExtra("GAME_SCORE",gameView.getHitCount());
      setResult(RESULT_OK, returnIntent);
      super.finish();
    }

I know I have to create a getHitCount field that will pass it to the intent but I'm not sure how to do this. The relevant field is called hitCount, I've also included where it is incremented.

 if (sprite.wasItTouched(event.getX(), event.getY())){
    /* For now, just renew the Sprite */
            sprite = new Sprite(this);
                hitCount++;         
            }

public void getHitCount() {

}
kendrick
  • 21
  • 2
  • You can read the Android Documentation for this. For the sake of answering, you can catch it by overriding `onActivityResult` – AC-OpenSource May 04 '15 at 04:23
  • 2
    this is what you're looking for http://stackoverflow.com/questions/10407159/how-to-manage-start-activity-for-result-on-android – Yurets May 04 '15 at 04:24

3 Answers3

0

Use startActivityForResult(intent); to get intent from next activity when it finished. You can get result in onActivityResult(..,..,.) method.

0

StartActivityForResult is good as suggested by the previous answer.

For the retrieving part

Well u can get the value using getIntExtra .but it consists of a argument called as default value. for that i suggest you provide the previous game score.

Intent in=this.getIntent();
hitCount = in.getIntExtra("GAME_SCORE",default_value);
Prasanth Perumal
  • 259
  • 1
  • 2
  • 4
0

Is you use setResult you get the Integer in the method startactivityforresult, I recommend you use a preference for save you number in disk and get this data in any other part in your app