Check If Activity Has Been Called for Result

血红的双手。 提交于 2019-11-27 01:26:12

问题


Is it possible to know if some activity has been called for result, using startActivityForResult() or if was only started using startActivity()?

I need to control this, if its called for result the behaviour will be different.


回答1:


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. 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 the startActivityForResult(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.



来源:https://stackoverflow.com/questions/16753657/check-if-activity-has-been-called-for-result

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!