开发者

what is result code or data returned by give intent

I am installi开发者_StackOverflow中文版ng 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?


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;
    }
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜