Covers how and when the lifecycle callback methods like onAttach, onCreateView etc. are being called when the fragment is created, destroyed, recreated or put in the backStack.
Questions tagged [fragment-lifecycle]
150 questions
0
votes
1 answer
Android - Activity/fragment lifecycle event when user closes app or OS closes app
I'm trying to call a function when user closes app manually (force close/manually closing through recent apps etc.) or when the OS closes the app to free up memory.
I'm doing database calls in my function.
My app architecture is based on fragments…

Franko Vlahov
- 11
- 2
0
votes
1 answer
Fragment returns null while reading from sharedpreferences file
I am reading string value from sharedpreferences in fragment but it return null sometime? Here is my logcat output:
java.lang.IllegalStateException: Fragment Home{fc6bf3a} (14420322-2dbf-46e9-9f52-12586f9fa36b) not attached to a context.
at…

usama
- 11
- 1
- 1
0
votes
2 answers
In an Android Fragment, why is a call to superclass not made on `onCreateView`?
Reading through "Head First Android Development", I noticed this issue on page 367.
The code is an implementation of a Fragment, and a couple of life cycle methods are overridden, namely onCreateView and onStart.
onStart() looks like…

mherzl
- 5,624
- 6
- 34
- 75
0
votes
1 answer
How to perform certain operations in a fragment inside a view pager before the activity is destroyed
My activity layout is as follows

Kartik
- 2,541
- 2
- 37
- 59
0
votes
1 answer
Fragment instances are kept in viewPager2 when host fragment removed
Have one activity app, where I have HomeFragment from which I open HostFragment, and HostFragment has ViewPager2 with 3 fragment items TabFragment1, TabFragment2 and TabFragment3.
When I open the HostFragment, and then go back, my tabFragments'…

Hayk Nahapetyan
- 4,452
- 8
- 42
- 61
0
votes
0 answers
Livedata observer, wait for onResume to complete and then use the data
I am unable to figure this out. I have scenario, I am getting the video data in background via viewModel, coroutine and result in LiveData. The call to viewModel happens in onViewCreated of fragment. And in onResume I initialise ExoPlayer.
Now if I…
user12297160
0
votes
1 answer
Call function after navigateUp or dismissing DialogFragment
Hi I'm using function loadExercises() in my app for setting data to recyclerview. For every part of my app it's working fine. But in one specific part I need two specific things:
Refresh view after DialogFragment dismiss() method. (I'm updating…

Lukáš Paták
- 1
- 1
0
votes
1 answer
At what point in the Fragment lifecycle is a RecyclerView ready?
I populate the RecyclerView like this:
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? {
val view = inflater.inflate(R.layout.player, container, false)
…

user1785730
- 3,150
- 4
- 27
- 50
0
votes
1 answer
testing androidx.fragment lifecycle by stopping and resuming with FragmentScenario, onCreateView() called twice but this bug is already fixed in 1.3.1
I'm writing instrumented tests for my app using androidx.fragment:fragment-testing. One of test cases is to check if all underlying logic behaves correctly when Fragment is stopped and resumed, to simulate app being minimized (home button) and…

Piotr Śmietana
- 393
- 2
- 19
0
votes
0 answers
Kotlin - fragment lifecycle navigation issues; why does child fragment become current destination?
Kotlin/Android novice. Please bear with me.
My app has the following navigation scheme: BottomNavigationView with navigationController where fragment One, Two and Three are "top destinations", from which I look to navigate further down in the…

Dan Abnormal
- 1,188
- 11
- 21
0
votes
0 answers
Understanding FragmentManager.getFragments() after detach because of "Error inflating class fragment"
I faced a problem debugging a code and the problem is that based on this:
public List getFragments ()
Get a list of all fragments that are currently added to the
FragmentManager. This may include those that are hidden as well as
those that are…

Alak
- 1
- 2
0
votes
1 answer
Relation between fragment and activity lifecycle
I have an activity A , and there are 2 fragments associated with this activity, lets us call them F1 and F2. Now there is a fragment switch between these fragments, so in this case is the onResume() activity lifecycle event of activity A called ?

Aabhas Gupta
- 65
- 6
0
votes
1 answer
Issues with multiple instances of same Fragment in ViewPager?
Context: SubFragment1
Desired result:
In onRefresh I want x to == z, in the example z is 1.
Problematic Result:
Solution
Removing the multiple instances of SubFragment1
FragmentPagerAdapter
@Override
public Fragment getItem(int position) {
…

Dylan
- 375
- 1
- 2
- 12
0
votes
2 answers
When/How to add ListView Adapter, that it gets restored with back button? (Fragment)
When / How to add a ListView Adapter, that it gets restored with back button?
I want to move back from FragmentB to Fragment A and have the same Adapter as I had before going to FragmentB.
@Override
public void onViewCreated(@NonNull View view,…

ximix424
- 75
- 6
0
votes
4 answers
Fragment BackStack lifecycle issues
I have a fragment activity, which has a fragment A. Fragment A does some important things in onViewCreated method:
@Override
public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) {
super.onViewCreated(view,…

NullPointerException
- 36,107
- 79
- 222
- 382