Monday, 5 May 2014

Avoiding double executing fragment element - i.e DialogFragment

In short example:

 //somewhere I create instance of my fragment  
 df = new DialogAllSectionsFragment().getInstance();  
   
 //when calling the fragment  
 Fragment fr = getSupportFragmentManager().findFragmentByTag(DialogAllSectionsFragment.TAG);  
 if (fr == null) {  
      df.show(getSupportFragmentManager(), DialogAllSectionsFragment.TAG);  
 }  

Every fragment element has own TAG with own name, so when fragmentManager finds the current tag exists it just doesn't call it again. It helps when user doubleclik one of our buttons.