android - Understanding fragments backstack -


Therefore, there are some similar questions, but I have not found any single person to solve this issue. Looks intuitive, but when I apply an application with a more complex workflow, pieces of backstacks become confusing and weird stuff starts up. I developed a skeleton for the simple app, which included the ideas of the same activity which can be used by its pieces to start the other pieces. How do I do this:

1- I let my main activity apply to an interface called "FragmentDelegate"

  public interface fragmentedgeget {public zero startup restriction (CC framework) Slice, boolean addToBackStack); 2-Implementation of the process of process:  
  @ Override Public Zero Start Restrictions (CC Fragment Piece, Boolean Adtoback Stacks) {Fragment Manager Slice Manager = getSupportFragmentManager ( ); Fragment.setFragmentDelegate (this); Piece Transaction Piece Transaction = Piece Manager. Section transaction Set custom animation (R.anim.slide_in_right, R.anim.slide_out_left, R.anim.slide_in_left, R.anim.slide_out_right); FragmentTransaction.replace (CONTENT_VIEW_ID, piece, "callerFragmentClassName"); If (adobecachex) piece transaction. Ad toubex stack ("callerfraagment classname"); FragmentTransaction.commitAllowingStateLoss (); }   

Good thing about this, I can call with any piece:

  mFragmentDelegate.startFragment (ANEFREGMENT, ADTOBACKSTACX);   

OK now think about the following case scenario:

I start my activity with a starting slice, say A to A, When I call the camera activity for the result when the result comes, I start the piece B (adding backstack). From B to I Fragment C Without , I connect backstack. That's why we say in the backstack:

[A] [C]

If I press the back button, then I come back to A. If I repeat the procedure, the backstack gets messed up and when I press back, then I take the piece of the piece repeatedly ...

I know that it is difficult to understand ( And difficult to understand for me, because English is not my mother tongue) but if someone can explain to me how Android pieces work actually work, or some type of app for Provide skeleton If so, then it would be nice.

"post-text" itemprop = "text">

Explanation:

When the fragment manager has defined fragment transmission (Like the user clicks the back button or you call it some pop method), it executes the opposite of the action stored in the saved fragment transaction. You can see the exact code, it is very straightforward.

In your case, the saved operation types are 'replaced', so that means removing all the added pieces of the piece and adding a deleted place again so when you have a piece of this type There is a heap: [B]

The fragment manager knows that, he has to remove the [B] piece example and [A] the problem on a pop operation is That is, you have changed [C] with [B]:

[A] [C]

Unfortunately Area, saved the pieces behind the rear entry do not know about the [C]. During a pop operation, the fragment manager will rejoin [A], will not get [b] then there is nothing about it, and leave [c] where it is.

Solution

A possible solution to this problem is using baby pieces. Piece-A is a top-level piece, but fragment-B is fragmented and fragments of a raffer fragment child.

Basically, when you go to Fragment-B, you replace Piece-A with rapperfragment in a secured transaction:

[A] [[b] ]

Then, when users go into fragment-C, you replace [B] of rapperfragment with only [C]:

[A] [ C]]

When the user presses the back button, we come back to the laminate A properly:

[A]

Demo

i this technology One has gathered one to display A.

Comments

Popular posts from this blog

Verilog Error: output or inout port "Q" must be connected to a structural net expression -

jasper reports - How to center align barcode using jasperreports and barcode4j -

c# - ASP.NET MVC - Attaching an entity of type 'MODELNAME' failed because another entity of the same type already has the same primary key value -