简体   繁体   English

这个 Android 代码是用来做什么的?

[英]For what this Android code is used?

I'm new on Android development, can you please explain me the following code and for what this Android code is it used?我是 Android 开发新手,能否请您解释一下以下代码以及它用于什么 Android 代码?

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

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 onActivityResult 方法用于处理从意图返回的数据,请在此处查看文档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.简而言之,在这种情况下,如果结果正常,并且我们有数据要处理,则会出现带有所选文件路径的 toast。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM