android - Check if Fragment exists in Fragment TabHost Activity -


I have an activity, which implements the fragment tab host with 2 tabs The first tab is a list view and The second tab is the same data in a detailed data view. Below is the code snippet from My Piece Activity:

  Find the Fragmentabhaostsubbiid (android.R.id.tabhost); MTabHost.setup (this, getSupportFragmentManager (), R. layout.action_list); MTabHost.addTab (mTabHost.newTabSpec ("Tab1"). Set indicator ("list"), ListFragment.class, null); MTabHost.addTab (mTabHost.newTabSpec ("Tab2") .Setindicator ("Extlist"), expandable listfreagment class, arg2);   

The issue now is that if I call again the pieces of its construction again, I need to check that the piece is already present, to add a new one Not required I tried under the stuff, but it is not working

  piece f = getSupportFragmentManager (). FindFragmentByTag ("list"); If (f! = Listed for blank & amp; amp; events) {Log.i ("ListActivity", "Already Created"); }   

For the above code, I am getting blank for the fragment F when the activity is called again Read some similar posts but nothing works, please advise how I It can be ensured that when the inventories are said that the pieces are not made again. Thank you.

I do not think it should be a matter of keeping a piece alive in its tabidity. If your activity is not destroyed, then you will not be fragments, but if your activities are destroyed, and even in pieces, it is not a major problem that they have been rebuilt, because the old example will soon be removed from the garbage collector Will be cleaned by. I do not understand why you want to control this behavior. Simply initialize your tabbar into the onCreate () of your activity, delete it in onDestroy () and let the Android Lifecycle do this work.

Comments

Popular posts from this blog

java - ImportError: No module named py4j.java_gateway -

python - Receiving "KeyError" after decoding json result from url -

.net - Creating a new Queue Manager and Queue in Websphere MQ (using C#) -