what is result code or data returned by give inten

2019-03-31 17:25发布

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

I would call install intent like

startActivityForResult(installIntent,requestCode);

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?

1条回答
Rolldiameter
2楼-- · 2019-03-31 18:06

The resultCode will be RESULT_CANCELED if the activity explicitly returned that, didn't return any result, or crashed during its operation.

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

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

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();

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;
    }
}
查看更多
登录 后发表回答