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 insetResult()will be sent to. You can use this
information to validate that the recipient is allowed to receive the
data.Note: if the calling activity is not expecting a result (that is it
did not use thestartActivityForResult(Intent, int)form that
includes a request code), then the calling package will be null.Returns
The ComponentName of the activity that will receive your reply, or null if none.