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() {
            @Override
            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);
                }
                startActivity(popup);

            }
        });

the popup:

public class PopUp extends Activity {

private OnSubmitListener mListener;

@Override
protected void onCreate (Bundle savedInstanceState){
    super.onCreate(savedInstanceState);
    requestWindowFeature(Window.FEATURE_NO_TITLE);
    setContentView(R.layout.popup_window);
    DisplayMetrics dm = new DisplayMetrics();
    getWindowManager().getDefaultDisplay().getMetrics(dm);
    int width = dm.widthPixels;
    int height = dm.heightPixels;
    WindowManager.LayoutParams windowManager = getWindow().getAttributes();
    windowManager.dimAmount = 0.75f;
    getWindow().addFlags(WindowManager.LayoutParams.FLAG_DIM_BEHIND);
    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() {
        @Override
        public void onClick(View v) {
            String additionalProduct = product.getText().toString();
            String additionalQuantity = qty.getText().toString();
            String additionalPrice = price.getTe        

Answers


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

 startActivityForResult(popup,1);

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
    setResult(100,data);

In MainActivity use the onActivityResult method to get the data

@Override
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

Search




Leave an answer