Check if operation was called for result

Is it possible to find out if any activity is called for the result using startActivityForResult() or if startActivityForResult() just started?

I need to manage this, if it was called for the result, the behavior will be different.

+66
android android-activity startactivityforresult result
May 25 '13 at 20:34
source share
1 answer

When your activity was only launched using startActivity() , the getCallingActivity() method in the target activity will return null .

When it was called startActivityForResult() , it will return the name of the calling activity.

See Docs for getCallingActivity() :

Returns the name of the action that caused this action. This is which data will be sent to setResult() . You can use this information to confirm that the recipient is allowed to receive data.

Note: if the calling activity does not expect a result (that is, it did not use the startActivityForResult(Intent, int) form, which includes the request code), then the calling packet will be empty.

Returns

The component_name of the activity that will receive your response, or null if it is absent.

+143
May 25 '13 at 20:46
source share



All Articles