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

The Archive Base Latest Questions

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

I have an application which has two Activities, let’s call them A and B.

  • 0

I have an application which has two Activities, let’s call them A and B. A is the initial Activity, and B is the second Activity. Once B is started, I do not want the activity to be destroyed until the application stops running, since B sets up an external network connection.

What I want is for people to enter the Activity at A, press the widget, and go to B, i.e. A -> B. If they press the back button on B, I do not want B destroyed. I don’t care if A is re-created or not, although by default it is not. The current activity is now A, if people press the widget to go to B, I want them to re-enter the existing B activity with the open network connection. If they press back again, I want them to go to the A activity. Now in A, if they press back, I want all activities in the application to close.

I have gotten somewhere with this in terms of creating an onBackPressed() method in B (so that the B activity is not destroyed when going to A). Also, adding the Intent flag “FLAG_ACTIVITY_REORDER_TO_FRONT” to the intent in A which calls B prevents B from being re-created when I call it a second time from A, although this may not be the best way.

To reiterate what I do:

  1. Enter application at Activity A.
  2. Press widget in A which opens Activity B.
  3. Press back button in B to open Activity A. This should not close B, but put it on the stack.
  4. Again in A. I press the widget for B. This should open up the existing B activity.
  5. Now in B I press back to get to A.
  6. Press back in A to exit the application.

The program flow is [Home screen] -> Activity A -> Activity B. Back keys will reverse this flow.

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

    Whenever an activity goes off the screen there is no way to guarantee that it won’t be killed by the OS. This means two things. Any visual state that you want to persists you must keep track of yourself. You can do this with the onSaveInstanceState and the onRestoreInstanceState.

    You mentioned that you want to open a network connection in an activity that might go off the screen. You should really consider doing this in a Service. Services are very similar to activities except they are designed to work off screen. They are great for doing something that doesn’t need user interaction.

    With regards to always having the back button switch between the two activities you can do this by intercepting the back button presses in your activity and then having your app switch activities. However remember that the back button has a very specific function on android and users are accustomed to apps behaving a certain way. Try not to do anything that flies in the face of the android UX conventions. Personally I find it frustrating when apps go against conventions like using the back button to exit out of activities and return to the home screen.

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

Sidebar

Related Questions

I have a server application in Java which has two simple operations, addTwoInts and
I have a VS 10 console application,which has to take two char inputs and
I have a J2EE application which has two web.xml files. One is called web.live.xml
I have an MVC application, which has two areas - Administrator, and User. What
I have a codeigniter web application which has two buttons guest or user. The
I have one Application which has more then 5 Activity I want to know
I have an ASP.NET application, which has two references added: MapServer and GDAL. These
I have an application which has two Tabs. Both of these are ListFragments. The
I have this simple MVC 3 application which simply has two controllers(Home and Edit),
I have an Android Honeycomb application with two activities; the first one has a

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.