public class BaseFragment
extends Fragment
A base class for Fragments that is capable of handling nested Fragments
and Activity-starts from those fragments with proper handing over of possible
result-codes from the activities to the appropriate fragment, which initially started the
Activity.
| Constructor and Description |
|---|
BaseFragment() |
| Modifier and Type | Method and Description |
|---|---|
protected boolean |
checkNestedFragmentsForResult(int requestCode,
int resultCode,
Intent data)
Checks to see whether there are any nested child fragments which have been
registered with a
requestCode before. |
Map<Integer,Fragment> |
getRequestCodesM()
Returns an unmodifiable
Map of the registered request codes. |
void |
onActivityResult(int requestCode,
int resultCode,
Intent data)
Receive the result from a previous call to
startActivityForResult(Intent, int). |
void |
registerRequestCode(int requestCode,
Fragment fragment)
Registers request code (used in
startActivityForResult(Intent, int)). |
void |
startActivityForResult(Intent intent,
int requestCode)
Call
Activity.startActivityForResult(Intent, int) on the fragment's
containing Activity. |
public void registerRequestCode(int requestCode,
Fragment fragment)
startActivityForResult(Intent, int)).requestCode - the request code.fragment - the fragment ID (can be Fragment#getId() of
Fragment#hashCode()public void startActivityForResult(Intent intent, int requestCode)
Call Activity.startActivityForResult(Intent, int) on the fragment's
containing Activity.
In addition to that, prior to making that call to the activity's startActivityForResult method,
this method checks whether it is the child of another Fragment. If that is the case and the
parent Fragment is also an instance of BaseFragment, it will register
the request code with the parent fragment and call its startActivityForResult-method, in order
to ensure that when the started Activity will return, the result-processing is
handed down to the correct fragment.
public void onActivityResult(int requestCode,
int resultCode,
Intent data)
Receive the result from a previous call to
startActivityForResult(Intent, int). This follows the
related Activity API as described there in
Activity.onActivityResult(int, int, Intent).
If there are nested fragments, this method will check if one of them has registered the result code and hands processing over to the appropriate fragment.
requestCode - The integer request code originally supplied to
startActivityForResult(), allowing you to identify who this
result came from.resultCode - The integer result code returned by the child activity
through its setResult().data - An Intent, which can return result data to the caller
(various data can be attached to Intent "extras").protected boolean checkNestedFragmentsForResult(int requestCode,
int resultCode,
Intent data)
requestCode before. If so, let it handle the
requestCode.requestCode - the code from onActivityResult(int, int, Intent).resultCode - the code from onActivityResult(int, int, Intent).data - the data from onActivityResult(int, int, Intent).true if the results have been handed over to some child
fragment. false otherwise.