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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T19:42:27+00:00 2026-05-27T19:42:27+00:00

I have an app that has a list of menu items. When you click

  • 0

I have an app that has a list of menu items. When you click a menu item it opens a corresponding activity. Now in that new activity when you click the back button and return to the main list, that activity gets killed and it does not return to its past state when you start it again.

My question is, is it possible to not kill the activity when you leave it?

I tried saving values like so:

 protected void onSaveInstanceState(Bundle outState) {
        super.onSaveInstanceState(outState); 
        outState.putString("TO_REMEMBER", "Remember this");
    }

However once the activity gets killed and than re-started, the oncreate method is not reading any data:

    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        if (savedInstanceState != null) {
//This is not getting fired                 
Toast.makeText(this, savedInstanceState.getString("TO_REMEMBER"), Toast.LENGTH_LONG).show();
                }
        }

Any help on this is appreciated.

  • 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-27T19:42:28+00:00Added an answer on May 27, 2026 at 7:42 pm

    Your are saving state using onSaveInstanceState but that is not meant to save state across activity life-cycle when you press back. That is meant to save state across orientation changes etc. That needs to be done if you want to save some state across orientation change, so you are right there.

    Now to save something across activity life-cycles, you have two options:

    • One, save your state to a persistent DB or something.
    • Second, if it is not to be stored in DB, then use getPreferences and store it using this. This will store it for that specific Activity only. I ll recommend this if you are trying to store the state of activity.

    Edit:

    Well leaving Activity alive is not a recommended/documented approach. You can have Service running in the background but does not contain UI as Activity does. If you press Home button instead of Back then it will act something like orientation change.

    In short, Activity is responsible for saving its state. That said, some UI controls save their state themselves so you dont have to save their state example EditText will save its state.

    Ref:

    getPreferences
    Shared Storage
    Saving Activity State

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an app that has a list of items. My customer prefers to
I have an app that has a list as its main activity and then
The main menu of my app is a list of items that has a
I have an app that has some configuration settings stored in SharedPreference. Now I
We have a GWT app that has multiple screens, based off of a menu.
I have an app that has a ConcurrentQueue of items that have an ID
I have an app that has the UIApplicationExitsOnSuspend info list property set to TRUE.
I have a web app that has a list of user comments. I want
I have a Rails app that has a COUNTRIES list with full country names
I have a WPF app that has a combobox with lookup items. The combobox

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.