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
6
votes
2 answers

Fragment does not respond to UI updates and eventbus events after resume

I have a SearchFragment class which extends a class called BaseFragment in which onResume and onStop are overridden as below: @Override public void onResume() { checkEventBusRegistration(); super.onResume(); } @Override public void onStop() { …
6
votes
4 answers

LifecycleObserver produce exception with methods that use newer APIs

My ViewModel class implements LifecycleObserver. When I call fragment.lifecycle.addObserver(this) it produces exception. Caused by: java.lang.IllegalArgumentException: The observer class has some methods that use newer APIs which are not available…
Andrii Turkovskyi
  • 27,554
  • 16
  • 95
  • 105
6
votes
2 answers

onMapReady is not called in the fragment

I am building an application which is related to google maps. In this i am trying to implement the map in fragment. I am manipulating the map in OnMapReady method. But app is not calling the OnMapReady method. I implemented the same thing in…
6
votes
2 answers

Where to restore fragment state that is inside ViewPager

Short Version: I have an Activity that has a ViewPager. The ViewPager has three fragments inside it. I am storing the data inside the fragments by implementing Parcelable and storing it inside the bundle. Now the question is where do I restore the…
6
votes
2 answers

Activity and Fragment Lifecycle, does the onResume fire one after the other?

I am wondering what the proper order goes when a user returns to an Activity from the Home Screen. Will the Activity's onResume() execute first, and then the Fragment's onResume() execute after? Does it do it in order, or will it do it…
6
votes
2 answers

Nested fragment lifecycle

I have 4 fragments. I switch among them by using hide/show transactions. One of them may have nested fragments which are added by replace transaction. The issue is that if I add a nested fragment hide main fragment and show it again the…
5
votes
0 answers

How to fix "FragmentManager is already executing transactions" error?

Ever since I updated my app implementations, I find myself unable to lunch the application. I am getting a "java.lang.IllegalStateException: FragmentManager is already executing transactions" error, and can't seem to find a solution to this…
5
votes
1 answer

How to prevent LiveData observers from being activated when Fragment is not visible

I want to use LiveData in a Fragment to observe the change of some data. Now let's suppose: Both the Fragment A and Fragment B have their own containers layout in Activity, which means we will call FragmentTransaction#add() separately for them and…
5
votes
1 answer

AppCompat Fragment lifecycle changed

After updating to new appcompat library com.android.support:appcompat-v7:25.1.0 I've got new fragment lifecycle when replacing fragments in transaction. E.g. I have two fragments FrFirst and FrSecond with logs in onStart and onStop, and I replace…
5
votes
1 answer

When does onActivityCreated get called in a Fragment's Lifecycle?

I am looking at the Fragment's Lifecycle here but cannot see where onActivityCreated gets called?
user1406716
  • 9,565
  • 22
  • 96
  • 151
5
votes
3 answers

android -does calling finish from activity destroy hosted fragment?

I have an 'Activity A' which host a 'Fragment B'. Please confirm that if I call A.finish() then 'fragment B 'gets destroyed. The fragment B would already be added to the fragment manager. I realize that a fragment is a sub-activity but i want to…
j2emanue
  • 60,549
  • 65
  • 286
  • 456
4
votes
4 answers

Fragment popbackstack trigger lifecyclescope collect

Situation I submit data setTripDeliver, the collect works fine (trigger LOADING and then SUCCESS). I pressed a button go to next fragment B (using replace). After that, I press back button (using popbackstack). the collect SUCCESS triggered. Codes…
4
votes
1 answer

Distinguishing static fragments from dynamic ones

Writing an android library, I'm listening to fragments' life-cycle using supportFragmentManager.registerFragmentLifecycleCallbacks. Having the fragment object in the callbacks, how can I check whether the fragment is a static fragment (defined in…
4
votes
3 answers

onResume of new Fragment called before onPause in Android Oreo 8.0

I am facing trouble with android Oreo. My MainActivity has 4 fragments, which replace each other whenever the user presses tabs. Now the problem is, I am saving a value in a singleton instance in onPause. Whenever the user presses the next tab,…
4
votes
4 answers

NullPointerException on Fragment Listener

I have a Activity with ViewPager, In ViewPager Adapter I provide Fragment for each position. An example Fragment is DebugFragment. I have written the source code below. public class DebugFragment extends android.support.v4.app.Fragment { private…
1
2
3
9 10