Dor Mesica
Dor Mesica

Reputation: 527

Stopping the onCreate() method

I want to use the startActivityForResult() method from the onCreate() method of another activity. My problem is that the onCreate() does not wait for the result of the new activity (that I called to using startActivityForResult()) and therefore the application stops.

Is there a way to tell onCreate() to stop until the new activity sends the result?

Upvotes: 0

Views: 85

Answers (2)

Toon Borgers
Toon Borgers

Reputation: 3658

An option i've seen to go to a login activity when the user's not yet logged in is the following:

  • Create an activity without any attached layout, make this your launcher activity
  • In its onCreate, check if the user is logged in.
  • If he is logged in -> go to the main activity
  • If he is not logged in -> go to login activity which goes to the main activity on successful login

Upvotes: 1

David Wasser
David Wasser

Reputation: 95578

In general, you can use startActivityForResult() in onCreate() to launch the login activity, but you can't wait for the results. You'll need to move all the code that onCreate() would normally do in onActivityResult() as that will be called when the login activity completes.

Upvotes: 3

Related Questions