android - Save state for onPause and onResume -


i'm not sure i've written title correctly, because first time feel have cope methods.

in oncreate(), make notification default sound printing string. then, check see if string. if isn't equal previous string, make notification sound. is, when find change location, make notification sound.

the problem want app run when in background, pause app, notification sound comes (the system doesn't remember i've made notification string, makes one). , again, open app, again notification.

i want make 1 notification 1 location if close , open app 100 times.

how can this?

hope explain problem.

public void oncreate(bundle savedinstancestate) {     super.oncreate(savedinstancestate);     requestwindowfeature(window.feature_no_title);     setcontentview(r.layout.map);     //here being called location listeners     somefunction(); } public void somefunction(){ //finally, after operation string if(newstring!=oldstring)     {         oldstring=newstring;         notification();      } }  public void notification(){ // here make notification default audio } 

i dont know if understand question quite right here code should you. code make application play once , save value future sessions of application, meaning wont play again unless save false value.

hope helps!

package stackoverflow.sound;  import android.app.activity; import android.content.sharedpreferences; import android.os.bundle;  public class playsound extends activity  {     private boolean hassoundbeenplayed;     private sharedpreferences settings;      public void oncreate(bundle savedinstancestate)      {         super.oncreate(savedinstancestate);         setcontentview(r.layout.main);          // gets values last session of application, check if sound played!         // if false no saved value found (first session of app)         this.settings = getpreferences(mode_private);         this.hassoundbeenplayed = settings.getboolean("hassoundbeenplayed", false);          // logics.. //          this.notification();     }      public void notification()     {         // if sound has been played, nothing         if (hassoundbeenplayed)             return;          this.hassoundbeenplayed = true;         // play sound     }      // if location changed, make notifications enabled again     public void changedlocation()     {         this.hassoundbeenplayed = false;          // whatever , play again         this.notification();     }      // called whenever application stops     protected void onstop()     {         super.onstop();          // whenever application stops, save sound boolean future sessions.         // if sound has been played (boolean = true), wont play on future sessions.         sharedpreferences.editor editor = this.settings.edit();         editor.putboolean("hassoundbeenplayed", this.hassoundbeenplayed);         editor.commit();      } } 

Comments

Popular posts from this blog

jquery - Invalid Assignment Left-Hand Side -

java - Play! framework 2.0: How to display multiple image? -

gmail - Is there any documentation for read-only access to the Google Contacts API? -