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

  • Home
  • SEARCH
  • 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 376585
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T14:36:49+00:00 2026-05-12T14:36:49+00:00

I have 3 different Activities that user navigates between in no particular order. My

  • 0

I have 3 different Activities that user navigates between in no particular order. My goal it twofold:

  1. When user switches to something else when app is resumed I want to start where user left even if app was terminated
  2. When last activity is resumed I want to restore it to the last viewed state (this one I think I have a pretty good idea on how to achive)

I think the problem is not start/stop – where I pretty much get what I need, but onCreate() if app was terminated. In that case – it picks Activity that I configured in the manifest. I suppose I can put something in onCreate() method of that default activity but is there a better way that I’m maybe missing?

  • 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-12T14:36:49+00:00Added an answer on May 12, 2026 at 2:36 pm

    If your app hasn’t been “terminated” then #1 should already work and #2 just requires saving any values that aren’t managed automagically into the Bundle in onSaveInstanceState() then restoring them in onRestoreInstanceState().

    This is kind of a hack, but I think your best option for #1 in the case of the app actually being terminated would be to save the most recent Activity in the onResume of each of your Activity classes then when you first run the onCreate of your first activity do a check then start the correct Activity… maybe even put in a blank Activity at the beginning. Something like this:

    StartActivity:

    public class StartActivity extends Activity {
        @Override
        public void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
    
            // get last open Activity
            String lastActivity = PreferenceManager.getDefaultSharedPreferences(this).getString("last_activity", "");
            if (last_activity == MyActivity2.getSimpleName()) {
                startActivityForResult(new Intent(this, MyActivity2.class));
            } else if (last_activity == MyActivity3.getSimpleName()) {
                startActivityForResult(new Intent(this, MyActivity3.class));
            } else {
                // assume default activity
                startActivityForResult(new Intent(this, MyActivity1.class));
            }
        }
    
        public void onActivityResult() {
            // kill the activity if they go "back" to here
            finish();
        }
    }
    

    Then in all the other Activities (MyActivity1,2,3) save the values like so:

    @Override
    public void onResume() {
        Editor e = PreferenceManager.getDefaultSharedPreferences(this).edit();
        e.putString("last_activity", getClass().getSimpleName());
        e.commit();
    
        super.onResume();
    }
    

    You’ll also have to handle saving /restoring the data for each Activity manually. You could save all the values you need into the preferences inside the onPause() of each of the Activities then restore it in the onResume().

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

Sidebar

Ask A Question

Stats

  • Questions 267k
  • Answers 267k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer If the names of the declared variables are the same… May 13, 2026 at 12:57 pm
  • Editorial Team
    Editorial Team added an answer have you tried: $'\x29' actually try this for ]: echo… May 13, 2026 at 12:57 pm
  • Editorial Team
    Editorial Team added an answer 1) If it meets your needs, then wouldn't that make… May 13, 2026 at 12:57 pm

Related Questions

I have 3 MySQL tables representing: photos a user post, videos a user post,
I have 3 different kinds of ajax popups that need to exist across my
I have 3 different jquery uses & put it into one code as follows:
I have 3 different transaction tables, which look very similar, but have slight differences.

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.