I have updated my app to use the latest support library (version 23.0.0), I've found out that they deprecated the onAttach() function of the Fragment class.
Instead of:
onAttach (Activity activity)
It's now:
onAttach (Context context)
As my app uses the activity passed before deprecation, a possible solution i think is:
@Override
public void onAttach(Context context) {
super.onAttach(context);
activity = getActivity();
}
Would that be the correct way to do it?
UPDATE:
If i run a device with API lower than 23, the new onAttach() is not even being called. I hope that this is not what they intended to do!
UPDATE 2:
Issue has been resolved with the latest updates to the SDK.
I have tested on my API 22 device and onAttach(Context) is being called.
Click here to follow the bug report I've opened a couple of weeks ago and the answers from the guys at Google.
Context
? Don't you need anActivity
in order to attach and display a fragment anyways? How else will you use theContext
parameter? – VitiateonAttach(Context context)
to be called, you need to either use a device that has at least API 23 OR use android.support.v4.app.Fragment. See here – Govern