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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T03:21:16+00:00 2026-06-05T03:21:16+00:00

I’m even not sure I’ve written the title correctly, because this is the first

  • 0

I’m even not sure I’ve written the title correctly, because this is the first time I feel I have to cope with this methods.

In onCreate(), I make a notification with default sound printing a string. Then, I check to see if I get another String. If it isn’t equal to the previous String, I make another notification with sound. That is, when I find that I change my location, I make a notification with sound.

The problem is that I want my app to run when it is in background, but as I pause the app, the notification with sound comes immediately (the system doesn’t remember that I’ve already made a notification for that string, it makes another one). And again, as I open the app, I again get the notification.

I want to make only 1 notification for one location even if I close and open app 100 times.

How can I do this?

Hope I could explain the problem.

public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    requestWindowFeature(Window.FEATURE_NO_TITLE);
    setContentView(R.layout.map);
    //here are being called location listeners
    somefunction();
}
public void somefunction(){
//finally, after some operation I get a string
if(newString!=oldString)
    {
        oldString=newString;
        notification(); 
    }
}

public void notification(){
// here I make notification with default audio
}
  • 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-05T03:21:18+00:00Added an answer on June 5, 2026 at 3:21 am

    I dont know if I understand your question quite right but here is code that should help you. This code will make the application play once and then save that value for future sessions of your application, meaning it wont play again unless you save a false value.

    Hope it 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 from last session of your application, check if sound was played!
            // If false no saved value was found (first session of your app)
            this.settings = getPreferences(MODE_PRIVATE);
            this.hasSoundBeenPlayed = settings.getBoolean("hasSoundBeenPlayed", false);
    
            // your logics.. //
    
            this.notification();
        }
    
        public void notification()
        {
            // If sound has been played, do nothing
            if (hasSoundBeenPlayed)
                return;
    
            this.hasSoundBeenPlayed = true;
            // Play your sound
        }
    
        // If location was changed, make notifications enabled again
        public void changedLocation()
        {
            this.hasSoundBeenPlayed = false;
    
            // Do whatever and play again
            this.notification();
        }
    
        // Called whenever application stops
        protected void onStop()
        {
            super.onStop();
    
            // Whenever application stops, save the sound boolean for future sessions.
            // If sound has been played (boolean = true), it wont play on any future sessions.
            SharedPreferences.Editor editor = this.settings.edit();
            editor.putBoolean("hasSoundBeenPlayed", this.hasSoundBeenPlayed);
            editor.commit();
         }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
this is what i have right now Drawing an RSS feed into the php,
I have this code to decode numeric html entities to the UTF8 equivalent character.
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I have this code: - (void)parser:(NSXMLParser *)parser foundCDATA:(NSData *)CDATABlock { NSString *someString = [[NSString
I have an MVC Razor view @{ ViewBag.Title = Index; var c = (char)146;
I have some data like this: 1 2 3 4 5 9 2 6
I have just tried to save a simple *.rtf file with some websites and
link Im having trouble converting the html entites into html characters, (&# 8217;) i
For some reason, after submitting a string like this Jack’s Spindle from a text

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.