Refreshing For Constant Fragments
Solution 1:
Finally I understood the fragment transaction behavior and how it works ...
Once you add/replace new fragment to Fragment Transaction you object is saved as initial state within Fragment Manager and when you try to detach the fragment and reattach [the same object] the Fragment Manager will get the object state which you passed it before to add()/replace() function.
So that's the reason of the result I got.
To simplify it.
- Suppose that you have an Class A extends from - Fragmentclass and this class contains- Integerobject have no value and have- Set()/- Get()methods.
- Now create an instance from this Class A and call - Set()function and pass value 1 to it. Then pass this instance to- Manager Transactionby- add()/replace()` method.
- Now try to call - Set()function and change the- Integerobject to another value.
- Detach the class A and reattach it and check the value of this object, you will get that the value of object return to initial value you assigned before passing the object to - Manger Transaction
Beside that there's an important note ... Fragment Transaction Actions like add(), replace(), remove() ... don't work at main thread and that's the reason of using commit() method and commitNow() method .. because when you use commit() your action will add to Fragment Transaction Queue so it will be executed after a bit of time but not now that's upon its order inside the queue, and so that you have another method called commitNow() to make your action execute immediately.
Post a Comment for "Refreshing For Constant Fragments"