Skip to content Skip to sidebar Skip to footer

Getactivity Return Null In Fragment Onactivitycreated In Some Rooted Device

My app work fine on most device but some rooted device. In fragment onActivityCreated, getActivity keep return null. I need Context class to to set up thing below. So anyone can he

Solution 1:

getActivity "might" return null if called from within onActivityCreated...especially during a configuration change like orientation change because the activity gets destroyed...move that initialization to onAttach...

@OverridepublicvoidonAttach(Activity activity) {
    super.onAttach(activity);
    //initialize here
}

onActivityCreated is a called when the parent activity's onCreate is called...but remember that it could be "recreated", destroyed during a config change

Post a Comment for "Getactivity Return Null In Fragment Onactivitycreated In Some Rooted Device"