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
1
vote
0 answers
Android app exception on restart_activity (lifecycle)
I am developing a simple app, but I got an error and I'm not quite sure why this error occurred.
I was playing a game and then exited the game. My app must be in the backstack because it gave me an error as soon as the game finished.
I took an event…

Wolf359
- 2,620
- 4
- 42
- 62
1
vote
0 answers
Viewpager with fragments: onAttached not called for all fragments?
I have been using Robospice to complete my network operations. In Robospice, they recommend that the SpiceService (an extension of the android service class) be started in a fragment's onAttach() method:
Other solution is to use second approach…

Simon
- 19,658
- 27
- 149
- 217
1
vote
1 answer
ViewPager doesn't show first fragment, if its contents are loaded dynamically
I am facing a very strange issue, while building a viewPager with fragments in android application. I have an activity, that builds the layout and two fragments: each of them contains RecyclerView and loads its contents dynamically from the server.…

Evgeniy Mishustin
- 3,343
- 3
- 42
- 81
1
vote
0 answers
What part of a fragment's lifecycle is activated by user tapping the overflow menu "settings dots icon"?
When the user hits the "settings dots" and pops up the menu shown, I want the timer to stop immediately (i.e., before user picks from the list), but I don't know where to put Timer.pauseTimer().
When the user taps one of the 4 items in the dropdown…

DSlomer64
- 4,234
- 4
- 53
- 88
1
vote
1 answer
Unable to resume activity IndexOutOfBoundsException: Invalid index 0, size is 0
I am getting a frustrating issue.
I have a list, and it has an adapter.
My adapter has an ArrayList, which holds references to ImageViews.
One of my fragments has a function for user to go and select a file from a directory of the…

vankiz
- 106
- 1
- 6
1
vote
0 answers
How to get height of view of one fragment to another fragment?
I have 3 tabs. 1 tab has a viewpager. I want to get the height of a view of a item in the viewpager so I can use it in my tab. If I try to access the fragment in onResume then the view is always null.
Layout for the Tab

MikeC
- 255
- 4
- 16
1
vote
1 answer
Lifecycle of Fragment that holds a ViewPager
I have something that has me stumped. I have a Fragment (Fragment A) that has ViewPager that contains three fragments (for swiping left/right). So, if within another fragment, in the onBackPressed() method, I do a…

Perry Hoekstra
- 2,687
- 3
- 33
- 52
1
vote
1 answer
Which mehtod is called if a fragment is not anymore in foreground?
I implemented an activity with a navigation drawer and a content fragment. The content fragment is replaced many times. But at some point I must provide a jumpback to a specific fragment with a specific state. I managed to save any required…

Bolic
- 705
- 2
- 12
- 30
1
vote
1 answer
Calling notifyDataSetChanged() on my adapter that is within a ListFragment causes a NullPointerException?
Introduction:
I have the following set up:
A MainActivity with methods onNewIntent and processNewIntent, the MainActivity also implements FragmentActivity; and has a tabbed fragment which implements FragmentList
A listaddactivity activity that…

Timothy Frisch
- 2,995
- 2
- 30
- 64
0
votes
0 answers
how to create resume and pause in one fragment to another when that one fragment ins running and restore it
i have one activity with 3 fragment using bottom navigation if i start my score_fragment inside has operation using button to textview in activity if i pause it and return with resume (draft )
Activity
public class FirstPlayedActivity extends…

Dwarakanath S
- 11
- 1
0
votes
0 answers
Switching between BottomNavigationView tabs, onDestroy of the fragment is called but still view restored on switching back. How?
I was exploring one of the navigation samples provided by Android here. Here each of bottom nav items has a nested graph of their own.
Currently I'm on the Second tab (Leaderboard) and on changing the tab, onDestroy() of the fragment gets called…
0
votes
2 answers
when I re-select menu items from bottom navigation view the fragments are recreating
I am using bottom navigation view with navigation components, when previous selected menu item is reselected fragment is reopening from oncreate
When I open my activity document fragment is loading and when I select even fragment and again reselect…

Ajay
- 11
- 1
0
votes
0 answers
Why does my app sometimes restart after a crash?
Faced with the following problem - my application restarts after a crash. This does not happen on all activities (activities with fragments located on them are used for navigation).
The following happens - when an exception is made, the application…

beet
- 16
- 2
0
votes
0 answers
Fragment Lifecycle - Why does this variable persist?
I'm declaring a variable in the scope of my fragment class (LocalDate?):
class HomeFragment : Fragment() {
private var _binding: FragmentMainBinding? = null
// This property is only valid between onCreateView and
// onDestroyView.
private val…
0
votes
1 answer
Detach Fragment when Activity gets recreated
When the activity gets recreated due to config-change or memory issues when in stack (going back to the activity stack) the attached fragment gets recreated as well.
In my case, the fragment cannot be recreated because it is linked to some…

htafoya
- 18,261
- 11
- 80
- 104