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 have already pass parameter `intent` to addToCart function, so instead of `advId = fromCart.getStringExtra("Advid");`, you can use `advId = intent.getStringExtra("Advid");`
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

```