检查如果活动已呼吁结果 [英] Check If Activity Has Been Called for Result

查看:94
本文介绍了检查如果活动已呼吁结果的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想知道,如果它可以知道如果有些活动已经呼吁的结果,或只是开始使用startActivity。

I would like to know if its possible to know if some activity has been called for result or only started using "startActivity".

我需要控制这一点,如果它的要求的结果的行为将是不同的。

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

在此先感谢!

推荐答案

当你的活动是由 startActivity开始只是() A getCallingActivity() 在目标活动的方法将返回

When your activity was started just by startActivity() a getCallingActivity() method in target activity will return null.

当它被称为 startActivityForResult()将返回调用活动的名字。

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

请参阅文档的 getCallingActivity ()

See Docs for getCallingActivity():

返回调用这个活动的活动的名称。这是   谁在的setResult数据()将被发送到。您可以使用此   信息来验证收件人允许接收   数据。

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.

请注意:如果调用活动没有期待的结果(这是它     没有使用 startActivityForResult(意图,INT)的形式,     包括:请求code),然后调用包将为null。

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.

返回

该活动的单元名,将得到您的答复,或者如果没有则为null。

The ComponentName of the activity that will receive your reply, or null if none.

这篇关于检查如果活动已呼吁结果的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆