Java tutorial
//package com.java2s; //License from project: Open Source License import android.content.Intent; import android.os.Build; import android.os.Bundle; import android.support.v4.app.ActivityCompat; import android.support.v4.app.Fragment; import java.lang.reflect.Field; public class Main { public static void startActivityForResult(Fragment fragment, Intent intent, int requestCode, Bundle options) { if (Build.VERSION.SDK_INT >= 19) { if ((requestCode & 0xffff0000) != 0) { throw new IllegalArgumentException("Can only use lower 16 bits" + " for requestCode"); } if (requestCode != -1) { try { Field mIndex = Fragment.class.getDeclaredField("mIndex"); mIndex.setAccessible(true); requestCode = ((mIndex.getInt(fragment) + 1) << 16) + (requestCode & 0xffff); } catch (NoSuchFieldException | IllegalAccessException e) { throw new RuntimeException(e); } } ActivityCompat.startActivityForResult(fragment.getActivity(), intent, requestCode, options); } else { fragment.getActivity().startActivityFromFragment(fragment, intent, requestCode); } } }