Questions tagged [fragment-lifecycle]

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.

150 questions
1
vote
3 answers

Is it mandatory to set databinding obejct to null inside onDestroyView()?

I read some articles where it is said that the best practice is to set databinding obejct to null inside onDestroyView() in a fragment: override fun onDestroyView() { super.onDestroyView() dataBinding = null } I've also seen this video…
1
vote
2 answers

How to Close ExoPlayer instance in ViewPager2 when swipe occurs

I have the following fragment handling a ViewPager2 which creates fragments (VideoFragment) on which a video is shown via ExoPlayer: private const val IMMERSIVE_FLAG_TIMEOUT = 500L class VideoGalleryFragment : Fragment() { private lateinit var…
1
vote
2 answers

How does fragment's lifecycle works inside viewpager? Why onStop is not called on navigation change?

I'm using ViewPager 2 from AndroidX with 4 instances of the same fragment. My question is pretty straight forward. When I'm navigating to some another fragment(using navigation drawer or even something else). OnStop() , OnDestroy(), OnDettach() of…
1
vote
1 answer

How to fix: onResume get called both before and after onActivityResult when the started activity finishes

I'm trying to call an activity using startActivityForResult() from a fragment. That activity basically does something and then gives the result back, but what happens, which is really weird is that, after the called activity finishes, the fragment…
1
vote
0 answers

Fragment setUserVisibleHint method is deprecated

I used this method to perform some task after the fragment was visible to the user. Now, this method is deprecated and I am unable to find a proper alternative method which gives a similar callback. As per the documentation they suggest to use…
Mittal Varsani
  • 5,601
  • 2
  • 15
  • 27
1
vote
1 answer

views null in onViewCreated

I'm developing an application with MVP arch. One of the sections is just 3 fragments with some textviews and edittexts. However, sometimes i will get null views (especially textview) in my second fragment. I put the init code in onViewCreated /…
1
vote
1 answer

setPrimaryItem() on FragmentPagerAdapter isn't called after going back to activity from background

When I launched my app, at the first time setPrimaryItem() was called, I added a new fragment to the host activity. This fragment got the data set from the current fragment on viewpager. I added it inside setPrimaryItem() because I wanted to make…
1
vote
1 answer

Do I have to set views to null in `onDestroyView()` for Fragments when used inside a ViewPager?

If I have a FragmentStatePagerAdapter with a many Fragments like this: public class MyFragment extends Fragment { View myView; @Override public void onViewCreated(View view, @Nullable Bundle savedInstanceState { myView = …
1
vote
1 answer

RecyclerView doesn't load data on first launch after Permission Check inside fragment

RecyclerView adapter doesn't load data on first launch after Permission check. I have to re-tap the tab to get the data. I have already visited/tried these links - -- RecyclerView doesn't load data in first launch using FirebaseRecyclerAdapter --…
1
vote
4 answers

Is there any way to detect if fragment is showing to user or not?

Here are simple steps. step1 : fragment1 was showing and it's already added to Backstack step2 : fragment2 is added to Backstack and showing it now step3 : fragment2 is removed from Backstack So finally, fragment1 is showing again to user. In this…
Passionate.C
  • 233
  • 3
  • 20
1
vote
1 answer

Fragment calls the same network call again

I have 2 fragments. In the first fragment there is a listview of items that I fetch from a server. and when I click a list item it will navigate to the second fragment with the details of the item I clicked. but when I press back and navigate to the…
1
vote
1 answer

Lifecycle of tabs in Android

I am using a TabLayout and a ViewPager to implement 5 tabs as the detail view of a master/detail layout. When I click on an item in the master view, it creates my detail view which in turn creates the necessary tabs. When the detail view is created,…
1
vote
3 answers

Complications with Viewpager

I am using a ViewPager and have 3 Fragments in it. I know that when the ViewPager loads for the first time it loads all the fragments by default , minimum is 3 fragments and viewpager executes all the lifecycle methods of fragments. Problems I…
1
vote
1 answer

When in a support Fragment lifecycle do all view(s) actually get displayed on the screen?

I have an Activity that displays various fragments using the supportFragmentManager. When I attempt to get a view in the fragment or the parent activity for that matter, and attempt to measure it's position on the screen it only seems to be…
1
vote
1 answer

How is OndestroyView called?

Say I have a Fragment and I have posted on UI handler from background thread, a runnable to modify Fragment before onDestroyView of Fragment was called. Is the posted runnable guaranteed to be called before onDestroyView will be called or can…