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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T05:21:16+00:00 2026-05-29T05:21:16+00:00

I am having two activities (activity1 and activiy2) and each activity is having one

  • 0

I am having two activities (activity1 and activiy2) and each activity is having one button each. In activity1 i having a spinner with few options. Suppose i am selecting option 2 from this spinner and i am clicking the button in activity1, then activity2 starts. When i click back button activity1 is resumed and the same option 2 is visible (like i need). Now the problem is that if my activity2 is started and i am clicking a button in it, activity1 is started. But instead of resuming the previous state of activity1 it starts in a way that it has just created and the previous selection is changed. How can i get the same facility like back button (not the facility of going back to previous activity, i mean automatically resuming the previous state of any activity) even when i start the activity again. Simply i need to know how to maintain the previous state of an activity if it is again visited.

It is with this code I go from one activity to another when button is clicked:

Intent intent=new Intent();
intent.setClassName(getApplicationContext(),"com.myapp.activityname");

startActivity(intent);

Kindly help me.I am a beginner in android, so if any one is giving the answer please explain it a bit. Thanks in adavnce

  • 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-29T05:21:16+00:00Added an answer on May 29, 2026 at 5:21 am

    Think I found the answer. Let me tell what I have done in simple words,

    Suppose i am having two activities activity1 and activity2 and i am navigating from activity1 to activity2(i have done some works in activity2) and again back to activity 1 by clicking on a button in activity1. Now at this stage I wanted to go back to activity2 and i want to see my activity2 in the same condition when I last left activity2.

    For the above scenario what i have done is that in the manifest i made some changes like this:

    <activity android:name=".activity2"
              android:alwaysRetainTaskState="true"
              android:launchMode="singleInstance">
    </activity>
    

    And in the activity1 on the button click event i have done like this:

    Intent intent=new Intent();
    intent.setFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT);
    intent.setClassName(this,"com.mainscreen.activity2");
    startActivity(intent);
    

    And in activity2 on button click event i have done like this:

    Intent intent=new Intent();
    intent.setClassName(this,"com.mainscreen.activity1");
    startActivity(intent);
    

    Now what will happen is that whatever the changes we have made in the activity2 will not be lost, and we can view activity2 in the same state as we left previously.

    I believe this is the answer and this works fine for me.

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

Sidebar

Related Questions

I am having two activities A and B. when i click the button in
I have two activities. One activity has the main game and the other activity
Having two forms, each in it's own jQuery UI tab, how can I post
How do I go about having two view models communicate with one another using
No one said that OrderedDictionary is having two copies of elements, one in a
I am having trouble integrating two products, one of which is mine and they
I am having two activities in my application. I want to pass tha array
Having two projects: one is a class library (a .dll assembly) and the other
I understand having one asterisk * is a pointer, what does having two **
Suppose an application already has a stack of activities, and then a new activity

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.