Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to open an activity, input data, and get back to the first activity with the data?
    text
    copied!<p>OK, the title isnt that much of a title but dont judge me.I've searched the website, and a lot other but i just dont seem to find the right answer. the problem is this:</p> <p>I've created an android app that has one main activity(Activity A), it opens another activity B, where i put in some data, that data should be transferred back into the first activity, and then recorded into the db.</p> <p>i do it like this:</p> <p>in actctivity A:</p> <p>-I call a new intent, and then <code>startActivityForResult()</code> method.</p> <p>in the second activity when i hit the save button this gets executed:</p> <pre><code>btnSave.setOnClickListener(new OnClickListener() { public void onClick(View v) { Intent i = new Intent(getApplicationContext(), MainActivity.class); i.putExtra("date", dateText.getText().toString()); i.putExtra("time", timeText.getText().toString()); i.putExtra("text", taskText.getText().toString()); setResult(100); startActivity(i); } }); </code></pre> <p>when i get back to the first activity (the main one) this method gets called.</p> <pre><code>protected void onActivityResult(int requestCode, int resultCode, Intent data) { if(resultCode==100) { i = getIntent(); String text = i.getStringExtra("text"); String date = i.getStringExtra("date"); String time = i.getStringExtra("time"); Toast.makeText(this, text + "-" + date + "-" + time, Toast.LENGTH_LONG).show(); } super.onActivityResult(requestCode, resultCode, data); } </code></pre> <p>with the toast message i only get null values which means the data wasn't transferred from the second activity back to the first. can someone help me please, and btw the data should be saved into a database, but that is another problem, i just mentioned it in case it may help on not complicating things for me later on.</p> <p>Thanks in advance :D</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload