android - Adding Multiple instance of the same fragment in back-stack, data of previous added instance persists -


i have common list fragment reuse inflating different lists.

i followed answer provided @devrimtuncer this question achieve it.

consider have 2 lists product , sales inflated using same list fragment.

if select products navigation drawer new of list fragment data related products loaded.

similarly, new instance related sales created if click sales option.

consider below scenario,

  1. if select products option followed sales option, separate instances of list fragment created , currently, sales list visible. product list in stack.

  2. further, if select products option, product list popped stack. contains data related sales list(somehow arguments in list fragment related b persists).

i use unique tags product , sales list fragments while inflating fragments.

below method use inflating fragment.

private void openlistfragment(bundle arguments, string listname) {     boolean fragmentpopped = mfragmentmanager.popbackstackimmediate (listname, 0);      if(!fragmentpopped && mfragmentmanager.findfragmentbytag(listname) == null)     {         mfragmentmanager                 .begintransaction()                 .replace(r.id.list_container, listfragment.newinstance(arguments))                 .addtobackstack(listname)                 .commit();     } } 

the listname parameter unique , b.

i kind of stuck this. please bare me if simple problem.

i able identify problem. small mistake end.

i using static variable save fragment instance inside list fragment. below scenario happened.

1) creation of product list.

a new instance of list fragment created , static variable pointing memory created.

2) creation of sales list.

a new instance of list fragment created static variable re-used since static , assigned new value.

3) popping product list stack.

the static variable still holding previous value , has sales fragment instance stored in it. popped fragment displaying wrong list.

i removed static variable , replaced normal variable , problem solved.


Comments

Popular posts from this blog

php - Permission denied. Laravel linux server -

google bigquery - Delta between query execution time and Java query call to finish -

python - Pandas two dataframes multiplication? -