The text below is selected, press Ctrl+C to copy to your clipboard. (⌘+C on Mac) No line numbers will be copied.
Guest
Xcbfxdgdf
By Guest on 14th March 2019 06:27:49 AM | Syntax: TEXT | Views: 4



New paste | Download | Show/Hide line no. | Copy text to clipboard
  1.     @Override
  2.     public void onBackPressed() {
  3.  
  4.         System.gc();
  5.  
  6.         if (!tag.equals("home")) {
  7.             if (getSupportFragmentManager().getBackStackEntryCount() > 1) {
  8.  
  9.                 for (int i = 0; i < getSupportFragmentManager().getBackStackEntryCount() - 1; ++i) {
  10.                     getSupportFragmentManager().popBackStack();
  11.                 }
  12.  
  13.                 tag = "home";
  14.                 tabSelection(true, false, false, false);
  15. //                setToolbarTitle(getString(R.string.app_name));
  16.                 pushFragment(new HomeFragment());
  17.  
  18.             } else {
  19.                 backPress();
  20.             }
  21.         } else {
  22.             backPress();
  23.         }
  24.     }
  25.  
  26.     private void backPress() {
  27.         if (doubleBackToExitPressedOnce) {
  28.             finish();
  29.             return;
  30.         }
  31.  
  32.         this.doubleBackToExitPressedOnce = true;
  33.         Toast.makeText(this, "Please click BACK again to exit", Toast.LENGTH_SHORT).show();
  34.  
  35.         new Handler().postDelayed(new Runnable() {
  36.  
  37.             @Override
  38.             public void run() {
  39.                 doubleBackToExitPressedOnce = false;
  40.             }
  41.         }, 2000);
  42.     }
  43.  
  44.     /**
  45.      * Method to push any fragment into given id.
  46.      *
  47.      * @param fragment An instance of Fragment to show into the given id.
  48.      */
  49.  
  50.     protected void pushFragment(Fragment fragment) {
  51.         if (fragment == null)
  52.             return;
  53.  
  54.         FragmentManager fragmentManager = getSupportFragmentManager();
  55.         if (fragmentManager != null) {
  56.             FragmentTransaction ft = fragmentManager.beginTransaction();
  57.             if (ft != null) {
  58.                 ft.replace(R.id.container, fragment).addToBackStack(null);
  59.                 ft.commit();
  60.             }
  61.         }
  62.     }



  • Recent Pastes