-1

I am currently working on an "Order food from home" restaurant app. What I am trying to do is to send the quantity of a product (a bottle of CocaCola for example) from the activity that includes only the juice to the "Shopping Cart" activity where I will calculate the price and then show both the quantity and the total price of the product.

My problem is that I can't really figure out how to send information from activity A to activity B.

If possible, I would like doing that without using a database. (Through intents for example) This code shows on the activity with the juice the quantity of CocaCola's the customer wishes to buy. I want to send this quantity in the shoppingCart activity.

Code:

public void displayCantitateCocaCola(int number){
    TextView quantityText = (TextView) findViewById(R.id.cantitateCola);
    quantityText.setText("" + number);
}

So, if the above method's display is 3, I want to get that value in the shopping cart activity.

Phantômaxx
  • 37,901
  • 21
  • 84
  • 115
slgnalin
  • 25
  • 6
  • 2
    The standard way to go is to store the quantity in memory within a java object , for example "order". Use Parceler to make it Parcelable and send it as intent data. Or just send the quantity value as an int extra. see https://developer.android.com/guide/components/intents-filters.html#Building – Andrew Lam Dec 08 '17 at 17:23

1 Answers1

0

did you try to send your data inside intent? when you are moving from activity a to b use this answer: https://stackoverflow.com/a/2091482/6565331 Fast answer: Activity A:

    Intent i = new Intent(A.this,B.class)
i.putExtra("key", YOUR VALUE);
Startactivity(i)

Activity B on create:

Int value=0; 
 Intent intent= getIntent();
 Bundle b = intent.getExtras();
 if(b!=null) { 
Int value =(Int) b.get("key");
} 
Mkhakpaki
  • 120
  • 2
  • 12