I am passing a putextra from first activity to second activity. I validate what was passed to second activity. I have this working like I intended. My question is how to pass a string value back to the first activity.
Here is where I call the second activity from first.
public void scannedItem(String barCode,String localArea){
Intent intent = new Intent(this,selectItemActivity.class);
intent.putExtra("Barcode",mScan);
intent.putExtra("Area",myArea);
startActivityForResult(intent,1);
// finish();
}
On second activity I am receiving data from first activity like so
protected void onCreate(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_select_item);
passedArea = getIntent().getExtras().getString("Area");
passedScan=getIntent().getExtras().getString("Barcode");
updateScreen();
}
I perform validation on the extras passed from first activity and would like to pass a single string back to the first activity. On second activity I have loaded a RecyclerViewer and on the onClick I have tried.
public void onSelectClick(View view){
String lSelectLocation = mLocations.getLocation();
Timber.d(lSelectLocation);
Intent intent = getIntent();
intent.putExtra("Location",lSelectLocation);
finish();
}
My question is at least two parts. 1.) what do I have wrong on second activity to pass the String value back. 2.) On first activity what is needed to receive the String back. I have tried onResume but the following is null.
protected void onResume() {
super.onResume();
final String sender=this.getIntent().getExtras().getString("Location");
if(sender != null)
{
this.receiveData();
Toast.makeText(this, "Received", Toast.LENGTH_SHORT).show();
}
}
I also have this method on first activity but it doesn't seem to get fired.
protected void onActivityResult(int requestCode,String requestLocation,Intent data){ mLoc.setText(requestLocation); }
I have learned a lot in the last few months in Java. I have years as VB.net programmer and sometimes get lost in the differences.
Thank you all in advance.