本文介绍了Give Intent返回的结果代码或数据是什么的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Intent安装软件包.我可以安装它,但这就是我想要做的.

I am installing a package using intent.I can install it alright, but this is what i want to do.

我会这样称呼安装意图

startActivityForResult(installIntent,requestCode);

现在我要检查OnActivityResult,我要安装的应用程序是否已实际安装?那么安装程序是否会返回任何指示此结果的结果代码或额外的数据?

now i want to check in OnActivityResult, whether the app i wanted to install was actually installed or not? So does installer return any result code or extra data indicating this?

推荐答案

但是您可以在完成子活动之前指定它,然后启动它:

But you can specify it before finishing the child activity, and initiate it:

* RESULT_CANCELED
* RESULT_OK
* RESULT_FIRST_USER
* [...]

从子活动返回之前(显式调用finish()之前或在onDestroy()方法内部)之前,您可以指定结果:

Before returning from your child activity (before explicitly calling finish() or inside the onDestroy() method), you can specify your result:

setResult(Activity.RESULT_CANCELED);
//optional:
finish();

要检查结果代码,您必须覆盖父活动的onActivityResult方法:

To check the result code, you have to override the onActivityResult method of your parent activity:

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data)
{
    super.onActivityResult(requestCode, resultCode, data);
    switch (resultCode)
    {
        case RESULT_OK:
            [...]
            break;
        case RESULT_CANCELED:
            [...]
             break;
        default:
            break;
    }
}

这篇关于Give Intent返回的结果代码或数据是什么的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

11-02 14:15