How can I identify what Fragments are current visible on screen?

时间:2015-06-25 18:52:58

标签: android android-studio

I have forked an Android application and wish to change the behavior of a specific fragment. How can I use Android Studio to identify what fragments are currently displayed on-screen so that I can navigate to the correct .java file in the source?

2 个答案:

答案 0 :(得分:2)

When you add the fragment to your transaction add a tag, fragmentTransaction.replace(android.R.id.container, homeFragment, "HOME_FRAGMENT"); After that, to check if fragment is currently displayed is easy : HomeFragment homeFragment = (HomeFragment)getFragmentManager().findFragmentByTag("HOME_FRAGMENT"); if (homeFragment != null && homeFragment.isVisible()) { // do whatever you want :) }

答案 1 :(得分:-1)

您可以使用应用程序的软件包名称浏览Logcat,然后通常会有一些相关的调用,例如onActivityDestroyed,从中可以看到需要处理的片段