简体   繁体   中英

Activity life cycle with fragments?

i have 1 Activity 1 fragment and 2 screens ...

the Activity has a first Screen

setcontentview(R.layout.main)

i am using Actionbar menu to go to second screen(fragment using fragment Manager)

the fragment has a Second Screen

when i close the fragment,its come to the first Screen but none of the method is called ,so i could not do some changes in activity screen

I have tried in onCreate(),onStart(),onResume().

i have tried with in oncreate

if (savedInstanceState==null)

    {
       //my functions

    }

The deal is that Fragment 's lifecycle callbacks differs of Activity 's ones. For your particular issue you may try to use to override onViewStateRestored method of your Fragment or onCreateView depends on how you manage your fragments when performing fragment transaction.

i have found answer myself

i called those methods when fragments when into pause state

@Override
public void onPause(){
    super.onPause();
   getActivity().somefunctions();
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM