The Fragment corresponding to the tab in FragmentTabHost is not OnDestoryView

Source: Internet
Author: User

Problem:

This interface jumps to the specific interface of a contact, but the fragment in does not execute the onPause (), onStop (), onDestoryView () method, therefore, the destroyed interface will affect the operations on the contact's specific interface.

Therefore, you have to manually destroy this interface, so before loading the contact's specific interface ()

Fragment = fm. findFragmentByTag ("0"). getChildFragmentManager (). findFragmentByTag ("contacts"); if (fragment! = Null) {Log. e (TAG, "contacts already exists"); // fragment. onPause (); // fragment. onStop (); // fragment. onDestroyView (); fm. beginTransaction (). hide (fragment ). commit ();}

At this point, if you click the return button on the contact's specific interface, the interface above will be blank because the interface is not shown by show (), so the listener returns the button, show () interface.

// Listener object rollback button. Only the focus is set for the view, and the rollback button and the up navigation button can be listened. setFocusableInTouchMode (true); view. requestFocus (); view. setOnKeyListener (new OnKeyListener () {@ Overridepublic boolean onKey (View v, int keyCode, KeyEvent event) {switch (keyCode) {case KeyEvent. KEYCODE_BACK: fragment = (ContactsFragmentTab) fm. findFragmentByTag ("0 "). getChildFragmentManager (). findFragmentByTag ("contacts"); fm. beginTransaction (). show (fragment ). commit (); break; default: break;} return false ;}});
Listening and navigation

@Overridepublic boolean onOptionsItemSelected(MenuItem item) {Log.e(TAG, "onOptionsItemSelected");switch (item.getItemId()) {case android.R.id.home:fragment = (ContactsFragmentTab) fm.findFragmentByTag("0").getChildFragmentManager().findFragmentByTag("contacts");fm.beginTransaction().show(fragment).commit();// called when the up affordance/carat in actionbar is pressed getActivity().onBackPressed();return true;default:return super.onOptionsItemSelected(item);}}


Note: For fragment reuse, it is best to place the interaction between fragment and other fragment in their activity and use interfaces to implement mutual operations. For more information, see the following blog posts:

Http://blog.csdn.net/zqx198810/article/details/9401475







Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.