检查如果活动已呼吁结果结果

2023-09-12 04:27:22 作者:余烬

我想知道,如果它可以知道如果有些活动已经呼吁的结果,或只是开始使用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.