Home Ask Login Register

Developers Planet

Your answer is one click away!

Erez Priel February 2016

how to retrieve values from popup to main?

I have a main Activity that calls a popup window:

AddProduct.setOnClickListener(new View.OnClickListener() {
            public void onClick(View v) {
                Intent popup = new Intent(SingleVoucher.this, PopUp.class);
                if (additionalProduct!=null) {
                    popup.putExtra("additionalamount", additionalQuantity);
                    popup.putExtra("additionalprice", additionalPrice);
                    popup.putExtra("additionalproduct", additionalProduct);


the popup:

public class PopUp extends Activity {

private OnSubmitListener mListener;

protected void onCreate (Bundle savedInstanceState){
    DisplayMetrics dm = new DisplayMetrics();
    int width = dm.widthPixels;
    int height = dm.heightPixels;
    WindowManager.LayoutParams windowManager = getWindow().getAttributes();
    windowManager.dimAmount = 0.75f;
    TextView SubmitAdditional = (TextView) findViewById(R.id.SubmitAdditional);
    final EditText product = (EditText) findViewById(R.id.adittionalTextEdit);
    final EditText qty = (EditText) findViewById(R.id.additionalQuantityTE);
    final EditText price = (EditText) findViewById(R.id.adittionalPriceTE);
    final Intent intent = getIntent();
    final Context context = this;
    SubmitAdditional.setOnClickListener(new View.OnClickListener() {
        public void onClick(View v) {
            String additionalProduct = product.getText().toString();
            String additionalQuantity = qty.getText().toString();
            String additionalPrice = price.getTe        


David Rauca February 2016

Try to use startActivityForResult in order to show the popup.

Here is an example: http://developer.android.com/training/basics/intents/result.html

Then in the main activity you should override onActivityResult in order to have access to the info you sent from popup.

N J February 2016

You will have to startActivityForResult()

then return result from PopUp Activity using setResult()

see this good link for statActivityForResult

Jiju Induchoodan February 2016

You can use startActivityForResult and setResult methods to achieve this. In MainActivity start the popup activity like this


In popup activity use the setResult method to pass the value back to main activity.

    Intent intent = new Intent();
    intent.putExtra("data",data); // data is the value you need in parent

In MainActivity use the onActivityResult method to get the data

protected void onActivityResult(int requestCode, int resultCode, Intent data) {     value = data.getBundleExtra("data");

Post Status

Asked in February 2016
Viewed 1,404 times
Voted 11
Answered 3 times


Leave an answer

Quote of the day: live life