views:

160

answers:

3

When my app starts, it checks to see if it has stored login credentials. if it doesn't, it starts another activity to prompt the user for those credentials. My problem is, that when the prompt activity is started, the first activity continues execution and ends up with null pointers because the prompt activity has not yet returned the needed data

public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    tv = new TextView(this);
    setContentView(tv);

    promptForLoginInfo(); //method creates intent and starts activity

    displayCredentials(); //prints data to screen
}

the output reads: "null" because the program executes "displayCredentials()" before the login prompt activity returns.

Anyone have a clue what to do?

+3  A: 

Your "promptForLoginInfo()" method should be calling startActivityForResult. Your "displayCredentials()" method should not be called in the onCreate() method, but in the onActivityResult method.

Chris Shaffer
thank you. now that this problem is resolved ill move on to the next
mtmurdock
A: 

Did you tried to check for stored credentials before calling displayCredentials()? If credentials are not found you can start activity by startActivityForResult() method and call displayCredentials() after your prompt activity finishes in onActivityResult().

Aleksander O
+1  A: 

In promptForLoginInfo(); you need to start activityForResult. then you need move displayCredentials(); from onCreate to onActivityResult

Alex Volovoy