Check If Activity Has Been Called for Result

When your activity was started just by startActivity() a getCallingActivity() method in target activity will return null. When it was called by startActivityForResult() it will return name of calling activity. See Docs for getCallingActivity(): Return the name of the activity that invoked this activity. This is who the data in setResult() will be sent to. … Read more

Using startActivityForResult, how to get requestCode in child activity?

You can pass request code by put extra. intent.putExtra(“requestCode”, requestCode); Or if you have used startActivityForResult many times, then better than editing each, you can override the startActivityForResult in your Activity, add you code there like this @Override public void startActivityForResult(Intent intent, int requestCode) { intent.putExtra(“requestCode”, requestCode); super.startActivityForResult(intent, requestCode); } So there is no need … Read more

How to manage startActivityForResult on Android

From your FirstActivity, call the SecondActivity using the startActivityForResult() method. For example: int LAUNCH_SECOND_ACTIVITY = 1 Intent i = new Intent(this, SecondActivity.class); startActivityForResult(i, LAUNCH_SECOND_ACTIVITY); In your SecondActivity, set the data which you want to return back to FirstActivity. If you don’t want to return back, don’t set any. For example: In SecondActivity if you want … Read more