How to use instanceof operator for fragment with class

Viewed 2944

I need to check the current displayed fragment to avoid relaunch of same fragment class

To launch the fragment used code :

private Class mFragmentClass;

mFragmentClass = InfoFragment.class;

if (null != mFragmentClass) {
  try {
     mFragment = (Fragment) mFragmentClass.newInstance();
     FragmentManager fragmentManager = getSupportFragmentManager();
     fragmentManager.beginTransaction().replace(R.id.content_navigation_menu, mFragment).commit();
  } catch (InstantiationException exception) {
     exception.printStackTrace();
  } catch (IllegalAccessException exception) {
     exception.printStackTrace();
  }
}

Need to check current displayed fragment:

if(mFragment instanceof (Fragment)mFragmentClass.newInstance())

is giving compile time error

[),Expected,Type Expected]

2 Answers
Related