From a file picker library on github,
When starting the file picker this code gets called, but there is another method which is the same but uses either getActivity() or getContext() depending on the build version:
I'm not sure which one i should use, what is the difference between getActivity and getContext?
First method:
public void start(@NonNull Activity activity, int requestCode) {
activity.startActivityForResult(createIntent(activity), requestCode);
}
Same method but different Context depending on build version:
@RequiresApi(api = Build.VERSION_CODES.HONEYCOMB)
public void start(@NonNull Fragment fragment, int requestCode) {
Context context;
if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.M) {
context = fragment.getContext();
} else {
context = fragment.getActivity();
}
if (context != null) {
fragment.startActivityForResult(createIntent(context), requestCode);
}
}