1

In my first Activity I made that you can open a pop-up window (it's another activity), where you can put some data in and it needs to be sent back to the original Activity. Since I will need to put the data I got into a ListView, I think I need to check if the button is pressend and in the onClick add to the ListView. How to do that?

Here's the code of the pop-up Activity:

public class AddCoin extends Activity {
    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        final Intent intentAdd = new Intent(this, PortfolioActivity.class);
        super.onCreate(savedInstanceState);

        setContentView(R.layout.add_coin_window);

        DisplayMetrics dm = new DisplayMetrics();
        getWindowManager().getDefaultDisplay().getMetrics(dm);

        int width = dm.widthPixels;
        int height = dm.heightPixels;

        getWindow().setLayout((int)(width*.8), (int)(height*0.4));

        Button add_coin = findViewById(R.id.add_toport_button);
        add_coin.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                EditText inputNameText = (EditText) findViewById(R.id.text_input_name);
                EditText inputPriceText = (EditText) findViewById(R.id.text_input_price);
                EditText inputAmmountText = (EditText) findViewById(R.id.text_input_ammount);

                String inputName = inputNameText.getText().toString();
                String inputPrice = inputPriceText.getText().toString();
                String inputAmmount = inputAmmountText.getText().toString();

                intentAdd.putExtra("Name", inputName);
                intentAdd.putExtra("Price", inputPrice);
                intentAdd.putExtra("Ammount", inputAmmount);

                finish();
            }
        });
    }
}
reVerse
  • 35,075
  • 22
  • 89
  • 84
Kazhiunea
  • 11
  • 3

3 Answers3

1

Proper way is calling activity with startActivityForResult().

But if you can not do this you can use EventBus

0

You can achieve this nature using startActivityForResult() method of Activity class.

Refer this link startActivityForResult

buzzingsilently
  • 1,546
  • 3
  • 12
  • 18
0

You have to use startActivityForResult(), put data into an Intent on called activity and then get results back using onActivityResult(int requestCode, int resultCode, Intent data) on the calling activity

E.Abdel
  • 1,992
  • 1
  • 13
  • 24