android - Funny things happening with putExtra and getIntExtra -


i'm developing game, on menu screen have series of buttons take player different levels of game. i've used putextra , getintextra take int menu activity game activity, sets play level.

this working nicely, problem having when using "back" button go menu activity have hit twice menu instead of once. if hit once takes level corresponds default int of getintextra function.

i'm not sure why it's doing this.

any advice appreciated.

-- edit --

in menu activity

 public void ongotogame1click(view view) {      intent getnamescreenintent = new intent(this, gameactivity.class);      final int result = 1;     startactivityforresult(getnamescreenintent, result);      getnamescreenintent.putextra( "int", 1);     startactivity(getnamescreenintent); } 

in game activity

@override protected void oncreate(bundle savedinstancestate) {     super.oncreate(savedinstancestate);     setcontentview(r.layout.game_layout);      leveltv = (textview) findviewbyid(r.id.level);      intent getnamescreenintent = getintent();     level = getnamescreenintent.getintextra("int", 1);      leveltv.settext(" " + level);  }  private void levelupdate() {      switch (score) {          case 10:             level = 2;             break;         case 20:             level = 3;             break;         case 30:             level = 4;             break;         case 40:             level = 5;             break; } 

you use both startactivityforresult() , startactivity(), activities started twice. first time without extra, second extra.

you should choose 1 or other. startactivityforresult() should used if need activity give result when finishes.

side note: second parameter of startactivityforresult() not result. request code allows caller know request answered when gets callback onactivityresult().


Comments

Popular posts from this blog

javascript - how to protect a flash video from refresh? -

visual studio 2010 - Connect to informix database windows form application -

android - Associate same looper with different threads -