Viewpager Loose Fragment Connection On Low Memory Kill
in my activity i use viewpager. I create two fragments and attach the to the view pager and time to time calling some methods from this fragments in my activity.. afer the app is k
Solution 1:
I found the solution....
it is really like a said that my fragment variables in the main activity is cleared so i have no connection to the fragments anymore.. what i did is inside the onAttach() i linked my fragment to the mainActivity variables again
@Override
public void onAttach(Activity activity) {
super.onAttach(activity);
mActivity = activity;
((RestaurantActivityViewPager)mActivity).menuFragment=this;
}
public static MenuFragment newInstance(int sectionNumber) {
MenuFragment fragment = new MenuFragment();
Bundle args = new Bundle();
args.putInt(ARG_SECTION_NUMBER, sectionNumber);
fragment.setArguments(args);
return fragment;
}
Solution 2:
If you get tabFragment by this code
Fragment fragment = mPagerAdapter.getItem(position);
It caused that bug when low memory. Try with this one
fragment = getSupportFragmentManager().findFragmentByTag("android:switcher:" + R.id.rewards_viewpager + ":"+position);
Post a Comment for "Viewpager Loose Fragment Connection On Low Memory Kill"