-6

I'm new on Android development, can you please explain me the following code and for what this Android code is it used?

public void onActivityResult(int requestCode, int resultCode, Intent data) {
    super.onActivityResult(requestCode, resultCode, data);

    try {

        if (requestCode == RESULT_LOAD_IMG && resultCode == getActivity().RESULT_OK
                && null != data) {

            selectedImage = data.getData();

            String[] filePathColumn = { MediaStore.Images.Media.DATA };
            // Get the cursor
            Cursor cursor = getActivity().getContentResolver().query(selectedImage,
                    filePathColumn, null, null, null);
            // Move to first row
            cursor.moveToFirst();
            int columnIndex = cursor.getColumnIndex(filePathColumn[0]);
            imgPath = cursor.getString(columnIndex);
            cursor.close();


            String fileNameSegments[] = imgPath.split("/");
            fileName = fileNameSegments[fileNameSegments.length - 1];
            _txt_img_url.setText(fileName);
            Toast.makeText(getActivity(), fileName, Toast.LENGTH_SHORT).show();

            ImageTask imgtask = new ImageTask();
            imgtask.execute();
Allan Pereira
  • 2,572
  • 4
  • 21
  • 28

1 Answers1

0

onActivityResult method is used to handle the data returned from an intent, check here the documentation https://developer.android.com/training/basics/intents/result.html

In short in this case if the result is ok, and we have data to handle, a toast appear with the path of the selected file.

Erik Minarini
  • 4,795
  • 15
  • 19
  • aww thanks alot :) i might have some more question related to android.I hope you will guide on those questions as well :) – Jibrael Khan Jun 19 '16 at 17:25