Ben
Ben

Reputation: 62366

How to pass data back to parent activity

On my app I see having multiple activities...

            Main
              |
     --------------------
   Login                 |
     |                   |
     --------------- Dashboard
                         |
     -----------------------------------------
     |                   |                   |
 Activity1           Activity2            Activity3

If a user is logged in, it will bypass login and head straight to dashboard. Then I see the dashboard launching other activities. Currently, my main activity looks like:

public class MainActivity extends Activity {
    User user = null;

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        startActivity(new Intent(this, LoginActivity.class));
    }
}

I've tried to find sample code showing how to pass data from my login activity back to Main, but I've been struggling. I can find many examples of how to pass data from a parent activity to a child activity, but not the other way around.

PS - If I'm not on the right track with my app, please let me know!

Upvotes: 4

Views: 2460

Answers (1)

Kaiesh
Kaiesh

Reputation: 1052

Have you looked into startActivityForResult?

Please see this tutorial: http://www.mybringback.com/tutorial-series/12186/android-startactivityforresult-example/

Upvotes: 5

Related Questions