Q:

using helper class to send and receive data using intent in android

enter image description hereI 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{

        }

    }
}

A:

You have already pass parameter intent to addToCart function, so instead of advId = fromCart.getStringExtra("Advid");, you can use advId = intent.getStringExtra("Advid");

