0

I am creating an app where I have 3 screens - Restaurant, Menu and Table in order. I need to push the restaurant ID generated in screen 1(Restaurant) to both screen 2(Menu) and screen 3 (Table). I am successfully able to push the restaurant ID to the menu screen but not able to do so to the table screen.

Intent intent = new Intent(getApplicationContext(), MenuActivity.class);
            intent.putExtra(RESTAURANT_ID, restaurant.getRestaurantID());
            startActivity(intent);

When I'm trying to push the restaurant ID to the table screen, a node is being created as 'restaurantID' not the unique auto-generated restaurantID.

Edric
  • 24,639
  • 13
  • 81
  • 91
  • 3
    Does this answer your question? [How do I pass data between Activities in Android application?](https://stackoverflow.com/questions/2091465/how-do-i-pass-data-between-activities-in-android-application) – itwasntme Dec 30 '19 at 06:04
  • Try using SharedPreference? https://stackoverflow.com/questions/46051658/how-to-save-data-by-using-sharedpreferences-in-a-fragment – Jason Dec 30 '19 at 06:45

2 Answers2

1

First retrieve the sent data from intent and then use it to pass to the another activity on launch

Bundle extras = getIntent().getExtras();
if (extras != null) {
    String componentName = extras.getString(RESTAURANT_ID);

    Intent intent = new Intent(this, TableActivity.class);
    intent.putExtra(RESTAURANT_ID, componentName);
    startActivity(intent);
}
jakshay
  • 86
  • 5
0

You can use broadcast receivers to send data to multiple activities. Passing Data from Broadcast Receiver to another Activity