Question: [enter image description here](https://i.stack.imgur.com/yqpJt.png)  

I want to fetch the data from previous activity (using getIntent) in a .java class and same the data to next activity through intent. can anyone help me how.Thanks in advance.

```
public class AddToCartHelper {

    public static void addToCart(Context context, Intent intent) {

        String TAG = "AddToCart";
        DecimalFormat decimalFormat;
        boolean loginflagforuser = false, loginflagforguest = false;

        String advId = "", num = "", uid = "", productName = "", emailCart = "",cartMessage = "";
        Double price = 0.0;
        Integer quantity = 1;

        SharedPreferences preferences = context.getSharedPreferences("SECRETFILE", Context.MODE_PRIVATE);

        loginflagforuser = preferences.getBoolean(Parameters.userEmail, false);
        loginflagforguest = preferences.getBoolean(Parameters.guestEmail, false);
        decimalFormat = new DecimalFormat("##.##");

        if (loginflagforuser){

            Intent fromCart = getIntent();
            //    imageId = fromCart.getStringExtra("image_url");
            advId = fromCart.getStringExtra("Advid");
            price = fromCart.getDoubleExtra("price", 0.0);
            num = fromCart.getStringExtra("num");
            uid = fromCart.getStringExtra("uid");
            Log.d(TAG, "--- REGISTERD UID::::::::: " + uid);
            quantity = fromCart.getIntExtra("quantity", 1);
            productName = fromCart.getStringExtra("cart_product_name");
            // total = fromCart.getDoubleExtra("total", 0.0);

            emailCart = preferences.getString("email", null);

        }else if (loginflagforguest){

        }else{

        }

    }
}

```

Answer: 
you don't need to use this Intent fromCart = getIntent();,because in constructor you already pass intent ,then just use intent object

```
dvId = intent.getStringExtra("Advid");
            price = intent.getDoubleExtra("price", 0.0);
            num = intent.getStringExtra("num");
            uid = intent.getStringExtra("uid");
            Log.d(TAG, "--- REGISTERD UID::::::::: " + uid);
            quantity = intent.getIntExtra("quantity", 1);
            productName = intent.getStringExtra("cart_product_name");
            // total = intent.getDoubleExtra("total", 0.0);

```
there is two ways to passing the data to the next activity you can either use intent or can use local broadcast receiver

if you want to fetch data from the previous activity then use

```
String a= getIntent().getStringExtra( "");// pass the name that you used in the previous activity

```