Search code examples
androidandroid-intent

get result of intent without OnActivityResult


I need to get the path of the result image path from intent without using the onActivityResult.

 Intent intent = new Intent();
 intent.setType("image/*");
 intent.setAction(Intent.ACTION_GET_CONTENT);
 startActivityForResult(Intent.createChooser(intent, "Select Picture"), SELECT_PICTURE); 

I need the path of the image to the next step in OnCreate which is after the this intent started. Is there any way to get this done without using OnActivityResult ??


Solution

  • I need the path of the image to the next step in OnCreate which is after the this intent started

    That is not possible. startActivityForResult() does not even begin doing its work until after your current callback (onCreate(), apparently) returns.

    Is there any way to get this done without using OnActivityResult ?

    No.

    I need the result image path to pass it to a new method and start a new intent.

    Do that in onActivityResult().

    this intent can be only created inside the onCreate due to my application structure

    That seems unlikely. Even if for some bizarre reason it is true, create the base Intent in onCreate(), store it in a field of your activity, and use the Intent in onActivityResult().