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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T01:08:33+00:00 2026-05-28T01:08:33+00:00

i have created an application its a music player with just a simple layout

  • 0

i have created an application its a music player with just a simple layout one button for play and stop. when i press the play button the music start to play and the play button change to stop button.. then when i press the back button the application goes in to background so i have to go to the menu and launch the application from there the problem is if i do that android starts a new instance of my application and the stop button is back to play button .. which i dont want to.. all i want is that android resume my application and bring it back to foreground and retain the state of all my buttons.

  • 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-05-28T01:08:34+00:00Added an answer on May 28, 2026 at 1:08 am

    When a user exits your app with the back button, your app is stopped and no state is saved. You’ll need to save whatever state you need to resume the app in one of the lifecycle methods like Activity.onStop. There is a good description of the activity lifecycle here.

    There is another section farther down called Saving Persistent State which talks a bit more about using Shared Preferences.

    [edit]

    I’m making some assumptions here about what your code might look like, but hopefully you can at least adapt these ideas to work with what you’ve got. Adding just a few things to your Activity will probably do the trick.

    You’ll want to be able to save the relevant settings when your app is closed:

    @Override
    public void onSaveInstanceState(Bundle icicle) {
        super.onSaveInstanceState(icicle);
        icicle.putString("path", mMediaPath);
        icicle.putInt("time", mMediaPlayer.getCurrentPosition());
        icicle.putBoolean("isPlaying", mMediaPlayer.isPlaying());
    }
    

    You’ll want to set up a method to initialize your media player from those settings. Something like this:

    private void initialize(String path, int time, boolean isPlaying) {
        mMediaPlayer.setDataSource(path);
        mMediaPlayer.seekTo(time);
        if (isPlaying) mMediaPlayer.start();
        findViewById(R.id.my_play_button).setBackgroundResource(isPlaying? R.drawable.pause_button: R.drawable.play_button);
    }
    

    Then, you can call that when your activity is recreated:

    @Override
    public void onRestoreInstanceState(Bundle icicle) {
        super.onRestoreInstanceState(icicle);
        String path = icicle.getString("path", DEFAULT_TRACK);
        int time = icicle.getInt("time", 0);
        boolean isPlaying = icicle.getBoolean("isPlaying", false);
        this.initialize(path, time, isPlaying);
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

hello i have created one windows application in c# .net and its working fine
I have created a Java desktop application. One of its buttons checks updates by
I have created an application.in the app i start a countdown timer and save
I have created one application on Vista, that is running with admin privileges. I
i have created a java application which uses data from its config folder and
I have created one application in iphone sdk. i have already taken user credit
I have created a MVC application its working fine. I have created a view
I have created one sample application , based on UIWebview sample and i added
I have created an android application and its running fine on my emulator.But the
I have created an application in c language and its executable file works fine

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.