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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T10:05:30+00:00 2026-05-31T10:05:30+00:00

I have created a simple app for android, that uses buttons to navigate different

  • 0

I have created a simple app for android, that uses buttons to navigate different activities the app starts at page 1, you click on page 2 or 3 button etc and that starts the required activity, simple.

What im having problems with (more of annoyance than problem) when you click HOME or come out of the app, because android doesn’t kill the app straight away it is keeping the page you are on remembered and is opening the app at activity 2 or 3 for example. I want the app when closed to go back to the beginning of the app again and open at 1, i can go back to 1 by clicking back but this is really not what i wanted.

I hope someone can read this and understand, simplest solution possible please

  • 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-31T10:05:31+00:00Added an answer on May 31, 2026 at 10:05 am

    What you need to do is use the Activity lifecycle to your advantage. When a screen is hidden for any reason, its onPause method gets called. When it’s displayed again, onResume gets called. However, onResume is called even the first time a new Activity is displayed. Another problem is that onPause is called when transitioning between Activities.

    So you ultimately want to “restart” the app when the last Activity’s onPause and onResume are called in succession. Try this class, and have all of your Activity’s extend this instead of Activity.

    public abstract class BaseActivity extends Activity {
    
        private static BaseActivity lastPausedActivity = null;
    
        @Override
        protected void onPause() {
    
            super.onPause();
            lastPausedActivity = this;
        }
    
        @Override
        protected void onResume() {
    
            super.onResume();
            if(this == lastPausedActivity) {
                lastPausedActivity = null;
                Intent intent = new Intent(this, FirstActivity.class);
                intent.setFlags( Intent.FLAG_ACTIVITY_CLEAR_TOP );
                startActivity( intent );
            }
        }
    }
    

    I haven’t tested this code, so it may need a few tweaks, but the logic should be sound.

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

Sidebar

Related Questions

I have created a small and simple android app. I tried installing it on
I have created a simple map app that shows the local garage sales in
I am trying to create a simple 3-D app for android that will have
I am writing a simple android app which have a edittext and a button.
So I created a simple hello world program that uses ksoap2 on Android 2.3
I have an simple android app that I want to write on the display
I have written a simple app for Android and when I first created the
I have created some simple app in Java, and 'deployed' it using Java Web
I have developed a very simple Android native app to launch my HTML5 webapp.
I am designing a simple app from tutorials that I have seen, and I

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.