1

I have a Fragment in which I display a response which is the details of a user, and that response contains information about other users(same json structure) and clicking on that link I inflate the same fragment(with different instance) which displays the information and this goes on and on everything is fine till here. Now when I press back key from last instance the previous fragment is not displayed and the last fragment with nth user data keeps on displaying.

Eg. Fragment A->(click on B profile)->Fragment A with B Profile->(click on C profile)Fragment A with C profile

when I backpress all I get is

Fragment A with C profile->Fragment A with C profile-> app closes.

and I'm adding the fragment to backstack with the following code.

ft.add(R.id.home_container_fl, baseFragment).addToBackStack(Fragment.class.getSimpleName()).commit();

I'm also using event bus for the same does that can affect this behaviour?

How can I fix the same?

Mohammed Rampurawala
  • 3,033
  • 2
  • 22
  • 32
Ankit Khare
  • 1,345
  • 11
  • 30
  • Please give a [mcve] which illustrates what you are trying to do. Also be more specific and precise in your wording. I have no idea what "the same" refers to. – Code-Apprentice Aug 22 '17 at 04:44

2 Answers2

0

One solution is to create different instances of the fragment each with its own data. This isn't ideal since you might create lots and lots of instances. However, it is fairly straightforward. Once you get something like this working, you can go back and try to find a solution which is more efficient with memory.

Code-Apprentice
  • 81,660
  • 23
  • 145
  • 268
0
 Bundle b = new Bundle();
 b.putInt("url", arrayList1.get(i));
 HomePageFragment f = new HomePageFragment();
 f.setArguments(b);
 fragments.add(f);

Try this code... it is assigning different data value to fragment.

Emanuel
  • 8,027
  • 2
  • 37
  • 56
PRATEEK BHARDWAJ
  • 2,364
  • 2
  • 21
  • 35