Android onActivityResult NEVER called

前端 未结 7 696
执笔经年
执笔经年 2020-12-04 03:03

my onActivityResult method is never called. am using android 2.2

I am using a Tabhost, where TabHosts contain TabGroups which contain individual Activities.

7条回答
  •  心在旅途
    2020-12-04 03:40

    Use the constant values for the Result codes:

    Activity.RESULT_OK and Activity.RESULT_CANCELED

    You'll see that the value for cancelled is actually 0. So in your code you are checking to see if the activity was cancelled.

    change your code to

    if (resultCode == Activity.RESULT_OK) {
    ...
    }
    

    Additionally change your Intent action to be:

    intent.setAction(Intent.ACTION_PICK);
    

    If you do this, you can just call

        Intent intent = new Intent(Intent.ACTION_PICK);
        intent.setType("image/*");
        startActivityForResult(intent, 0); 
    

    instead of creating the chooser. It will automatically pick the activities associated with that intent and mimetype and display them to you

提交回复
热议问题