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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T06:34:42+00:00 2026-05-16T06:34:42+00:00

My first activity is creating a second activity within its onCreate: if (userName ==

  • 0

My first activity is creating a second activity within its onCreate:

if (userName == null || password == null) {
    if (!getUserNameAndPassword() ) {
        // User is launching this for the first time
        Intent explicitIntent = new  Intent(CreateSessionAlert.this,CreateUserNameAndPassword.class);<br>
        startActivityForResult(explicitIntent,GET_USER_NAME_AND_PASSWORD);
    }
}

The second activity has EditText views for the username and password along with submit and cancel buttons. When either button is pushed, the text from username and password is sent back to activity one (via onActivityResult), which connects to a server to see if the username is available. While connecting to the server showDialog is used to show a ProgressDialog. When the server responds, the ProgressDialog is dismissed and an AlertDialog is shown. This works fine as long as the device is not rotated.

Here’s the problem: if the user rotates the device from within the second activity and pushes submit, the first activity re-invokes its onCreate, which ends up launching the second activity again since the username and password are still null.

Does anyone have any suggestions to get around this?

Is there a method that could be used to pass data from activity-2 to activity-1’s onCreate? I wouldn’t want to use a database in this case, as that seems like overkill.

I’ve thought about containing the server communication and dialogs to activity 2, but then I’d have duplicate server code in activity 1 and activity 2 (activity 1 connects to the server for other things too). Another issue I’d have with this approach is that the user has an option to cancel creating the password, in which case I want the app to finish. If I called finish from activity 2, activity 1 would appear and I don’t want that to show unless a username and password have been created.

It just occurred to me – if I could replace activity 2 with a dialog it might make things simpler. The dialog view needs to have 2 EditTexts and 2 buttons. Can I create something like this and use the showDialog method? Any other ideas?

  • 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-16T06:34:43+00:00Added an answer on May 16, 2026 at 6:34 am

    You can just add:

    <activity android:name="..."
          android:label="@string/appName"
          android:configChanges="keyboardHidden|orientation" />
    

    to the activity in your manifest. This will prevent the activity from being destroyed on the screen rotation.

    Beware that you still have to save the state of your activities in the onPause method. Just test what happens if you press the home button while the user logs in or recieve a call during logging in. This should remove your Activity from the memory and some more problems may occur.

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

Sidebar

Ask A Question

Stats

  • Questions 530k
  • Answers 530k
  • 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 I was actually able to finally find a solution that… May 16, 2026 at 11:38 pm
  • Editorial Team
    Editorial Team added an answer Use: SELECT r.*, COALESCE(x.totalbet, 0) AS totalbet, COALESCE(x.totalwins, 0) AS… May 16, 2026 at 11:38 pm
  • Editorial Team
    Editorial Team added an answer If you have multiple cores it can go over 100,… May 16, 2026 at 11:38 pm

Trending Tags

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

Top Members

Related Questions

I am confirming about creating activity. My Manifest.xml is like this : <application android:icon=@drawable/icon
This question actually has two parts. The first part: I've been developing my first
First of all let me say that this questions is slightly connected to another
I have some problem with passing a WebView from the first activity to the
New Android developer here. I'm following a tutorial at http://www.vogella.de/ . The first applications
I am creating a replacement Car Home app for Android 2.0+ devices. The app
I have an application I am creating with a DashboardActivity & a SettingsActivity. On
As per the android developer docs for creating tab UI you need to have
Sorry, I know that this topic has been covered a bit. I've read the
I am creating all of the elements in my android project dynamically. I am

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.