Note that there are some explanatory texts on larger screens.

plurals
  1. POissue with program flow when rotating device with two activities
    text
    copied!<p>My first activity is creating a second activity within its onCreate:</p> <pre><code>if (userName == null || password == null) { if (!getUserNameAndPassword() ) { // User is launching this for the first time Intent explicitIntent = new Intent(CreateSessionAlert.this,CreateUserNameAndPassword.class);&lt;br&gt; startActivityForResult(explicitIntent,GET_USER_NAME_AND_PASSWORD); } } </code></pre> <p>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.</p> <p>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.</p> <p>Does anyone have any suggestions to get around this?</p> <p>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.</p> <p>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.</p> <p>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?</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload