and I Have an issue which I wanted to do this sending data type in a Soft Button which I'd made and the softKey which is the default in every Android Device, so I've done this, first I've made an Intent
in my "A" Activity
:
Intent intent = new Intent();
intent.setClass(context, _AddNewEmployee.class);
intent.setFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT);
startActivityForResult(intent, 6969);
setResult(60);
Then in my second Activity, I've declared a Field in my "B" Activity
:
private static int resultCode = 40;
then after I made my request successfully or whenever I wanted to tell the "A" Activity that this job is successfully done here change the value of resultCode to the same I've said in "A" Activity
which in my case is "60" and then:
private void backToSearchActivityAndRequest() {
Intent data = new Intent();
data.putExtra("PhoneNumber", employeePhoneNumber);
setResult(resultCode, data);
finish();
}
@Override
public void onBackPressed() {
backToSearchActivityAndRequest();
}
PS: Remember to remove the Super
from the onBackPressed Method if you want this to work properly.
then I should call the onActivityResult
Method in my "A" Activity as well:
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if (requestCode == 6969 && resultCode == 60) {
if (data != null) {
user_mobile = data.getStringExtra("PhoneNumber");
numberTextField.setText(user_mobile);
getEmployeeByNumber();
}
}
}
that's it, hope it helps you out. #HappyCoding;
startActivityForResult
– InducteeActivity2
puts the value in persistent storage andActivity1
reads it from there. – Typewriter