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