Example usage for android.app FragmentTransaction add

List of usage examples for android.app FragmentTransaction add

Introduction

In this page you can find the example usage for android.app FragmentTransaction add.

Prototype

public abstract FragmentTransaction add(@IdRes int containerViewId, Fragment fragment);

Source Link

Document

Calls #add(int,Fragment,String) with a null tag.

Usage

From source file:com.google.cloud.solutions.cloudadventure.GameActivity.java

/**
 * Shows the {@link PreGameFragment} game lobby screen and creates a new {@link Player}. This
 * method is called almost immediately, within the Activity's onCreate().
 *//*from   www.  j  av a 2  s .  c  o  m*/
private void joinGame() {
    // Show the pre-game lobby screen
    FragmentManager fragmentManager = getFragmentManager();
    FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction();
    mPreGameFragment = new PreGameFragment();
    fragmentTransaction.add(R.id.game_activity, mPreGameFragment);
    fragmentTransaction.commit();

    new JoinGame().execute(mGameId, mHandle);
}

From source file:com.google.cloud.solutions.cloudadventure.GameActivity.java

/**
 * This method is called when the Activity receives a message via {@link BroadcastRecevier} that
 * the game has ended.//  w w w.  j a  v a  2 s.c  o  m
 */
private void onGameEnd() {
    FragmentManager fragmentManager = getFragmentManager();
    FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction();
    mScoresFragment = new GameScoresFragment();
    mScoresFragment.setCurrentUserHandle(mHandle);
    fragmentTransaction.add(R.id.game_activity, mScoresFragment);
    fragmentTransaction.commit();

    new SaveScoresAndSend().execute(mHandle, mGameId, Long.toString(mPlayer.getGemsCollected()),
            Long.toString(mPlayer.getMobsKilled()), Long.toString(mPlayer.getNumDeaths()));
}

From source file:com.cloudbees.gasp.activity.ReviewActivity.java

private void addGaspFragments() {
    FragmentManager fm = getFragmentManager();
    FragmentTransaction ft = fm.beginTransaction();

    mGaspReviewFragment = new GaspReviewFragment() {
        @Override/*from w  w w  .j ava2 s  .c om*/
        public void onSuccess(String location) {
            try {
                Log.d(TAG, "Gasp! review added: " + location);
                addGaspEvent(mPlacesReference, new URL(location));
            } catch (Exception e) {
                e.printStackTrace();
            }
        }

        @Override
        public void onFailure() {
            Log.e(TAG, "Error adding Gasp! review");
        }
    };
    mAddEventFragment = new AddEventFragment() {
        @Override
        public void onSuccess(EventResponse eventResponse) {
            Log.d(TAG, "Event added: " + eventResponse.getEvent_id());
        }

        @Override
        public void onFailure(String status) {
            Log.d(TAG, "Error adding event to Google Places API");
        }
    };

    ft.add(mGaspReviewFragment, "Gasp Review Fragment");
    ft.add(mAddEventFragment, "Add Event Fragment");
    ft.commit();
}

From source file:com.hit.jj.mapshow.RoutingActivity.java

/**
 * ?/*  w  ww.j a v  a  2  s  .  c  o  m*/
 */
private void setListener() {

    /**
     * On single clicking the directions label, start a ListActivity to show
     * the list of all directions for this route. Selecting one of those
     * items will return to the map and highlight that segment.
     *
     */
    directionsLabel.setOnClickListener(new View.OnClickListener() {

        public void onClick(View v) {
            if (mPaths == null)
                return;
            isStart = true;

            for (int i = 0; i < mPaths.size(); i++) {

                final Path path = mPaths.get(i);//?
                final int finalI = i;
                new Handler().postDelayed(new Runnable() {
                    @Override
                    public void run() {
                        switch (path.getNextDirection()) {
                        case 1:
                            speak("?");
                            break;
                        case 0:
                            speak("");
                            break;
                        case 2:
                            speak("??");
                            break;
                        }
                        clearAll();
                        pathfingding(mPaths, finalI);
                    }

                }, 10000);
            }
        }

    });
    img_cancel.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {

            clearAll();
        }
    });

    img_currLocation.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            Log.e("mLocation", mLocation.getX() + " " + mLocation.getY());
            Point p = (Point) GeometryEngine.project(mLocation, egs, wm);
            map.zoomToResolution(p, 20.0);

        }
    });

    img_getDirections.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            FragmentManager fm = getFragmentManager();
            FragmentTransaction ft = fm.beginTransaction();
            RoutingDialogFragment frag_dialog = new RoutingDialogFragment();
            ft.add(frag_dialog, "Dialog");
            ft.commit();

        }
    });
    img_speak.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            FragmentManager fm = getFragmentManager();
            FragmentTransaction ft = fm.beginTransaction();
            SpeakDialogFragment frag_dialog = new SpeakDialogFragment();
            ft.add(frag_dialog, "SpeakDialog");
            ft.commit();

        }
    });

    /**
     * On single tapping the map, query for a route segment and highlight
     * the segment and show direction summary in the label if a segment is
     * found.
     */
    map.setOnSingleTapListener(new OnSingleTapListener() {
        private static final long serialVersionUID = 1L;

        public void onSingleTap(float x, float y) {
            // Get all the graphics within 20 pixels the click
            int[] indexes = hiddenSegmentsLayer.getGraphicIDs(x, y, 20);
            // Hide the currently selected segment
            hiddenSegmentsLayer.updateGraphic(selectedSegmentID, segmentHider);

            if (indexes.length < 1) {
                // If no segments were found but there is currently a route,
                // zoom to the extent of the full route
                if (curRoute != null) {
                    map.setExtent(curRoute.getEnvelope(), 250);
                    directionsLabel.setText(routeSummary);
                }
                return;
            }
            // Otherwise update our currently selected segment
            selectedSegmentID = indexes[0];
            Graphic selected = hiddenSegmentsLayer.getGraphic(selectedSegmentID);
            // Highlight it on the map
            hiddenSegmentsLayer.updateGraphic(selectedSegmentID, segmentShower);
            String direction = ((String) selected.getAttributeValue("text"));
            double time = ((Double) selected.getAttributeValue("time")).doubleValue();
            double length = ((Double) selected.getAttributeValue("length")).doubleValue();
            // Update the label with this direction's information
            String label = String.format("%s%n%.1f minutes (%.1f miles)", direction, time, length);
            directionsLabel.setText(label);
            // Zoom to the extent of that segment
            map.setExtent(selected.getGeometry(), 50);
        }

    });

    /**
     * On long pressing the map view, route from our current location to the
     * pressed location.
     *
     */
    map.setOnLongPressListener(new OnLongPressListener() {

        private static final long serialVersionUID = 1L;

        public boolean onLongPress(final float x, final float y) {
            final Point loc = map.toMapPoint(x, y);
            //                Point  s1= new Point(26.0734997,119.3150024);
            Point s1 = new Point(26.1023006, 119.2789993);
            Point s2 = new Point(mLocation.getY(), mLocation.getX());
            Point sp = new Point(loc.getY(), loc.getX());
            pathfind(s2, sp);//
            //  pathfind(s1,sp);//
            return true;
        }

    });
}

From source file:org.proninyaroslav.libretorrent.fragments.MainFragment.java

private void saveTorrentError(Throwable e) {
    if (e == null) {
        return;//  w  ww . j  ava 2s.  c  o  m
    }

    sentError = new Exception(e);

    if (e instanceof FileNotFoundException) {
        ErrorReportAlertDialog errDialog = ErrorReportAlertDialog.newInstance(activity.getApplicationContext(),
                getString(R.string.error), getString(R.string.error_file_not_found_add_torrent),
                Log.getStackTraceString(e), R.style.BaseTheme_Dialog, this);

        FragmentTransaction ft = getFragmentManager().beginTransaction();
        ft.add(errDialog, TAG_SAVE_ERROR_DIALOG);
        ft.commitAllowingStateLoss();

    } else if (e instanceof IOException) {
        ErrorReportAlertDialog errDialog = ErrorReportAlertDialog.newInstance(activity.getApplicationContext(),
                getString(R.string.error), getString(R.string.error_io_add_torrent), Log.getStackTraceString(e),
                R.style.BaseTheme_Dialog, this);

        FragmentTransaction ft = getFragmentManager().beginTransaction();
        ft.add(errDialog, TAG_SAVE_ERROR_DIALOG);
        ft.commitAllowingStateLoss();

    } else if (e instanceof FileAlreadyExistsException) {
        Snackbar.make(coordinatorLayout, R.string.torrent_exist, Snackbar.LENGTH_LONG).show();
    } else {
        ErrorReportAlertDialog errDialog = ErrorReportAlertDialog.newInstance(activity.getApplicationContext(),
                getString(R.string.error), getString(R.string.error_add_torrent), Log.getStackTraceString(e),
                R.style.BaseTheme_Dialog, this);

        FragmentTransaction ft = getFragmentManager().beginTransaction();
        ft.add(errDialog, TAG_SAVE_ERROR_DIALOG);
        ft.commitAllowingStateLoss();
    }
}

From source file:org.proninyaroslav.libretorrent.fragments.MainFragment.java

@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
    switch (requestCode) {
    case TORRENT_FILE_CHOOSE_REQUEST:
        if (resultCode == Activity.RESULT_OK) {
            if (data.hasExtra(FileManagerDialog.TAG_RETURNED_PATH)) {
                String path = data.getStringExtra(FileManagerDialog.TAG_RETURNED_PATH);

                try {
                    addTorrentDialog(Uri.fromFile(new File(path)));

                } catch (Exception e) {
                    sentError = e;//from   w w w. j  a  v  a2s. c  om

                    Log.e(TAG, Log.getStackTraceString(e));

                    if (getFragmentManager().findFragmentByTag(TAG_ERROR_OPEN_TORRENT_FILE_DIALOG) == null) {
                        ErrorReportAlertDialog errDialog = ErrorReportAlertDialog.newInstance(
                                activity.getApplicationContext(), getString(R.string.error),
                                getString(R.string.error_open_torrent_file), Log.getStackTraceString(e),
                                R.style.BaseTheme_Dialog, this);

                        FragmentTransaction ft = getFragmentManager().beginTransaction();
                        ft.add(errDialog, TAG_ERROR_OPEN_TORRENT_FILE_DIALOG);
                        ft.commitAllowingStateLoss();
                    }
                }
            }
        }
        break;
    case ADD_TORRENT_REQUEST:
        if (resultCode == Activity.RESULT_OK) {
            if (data.hasExtra(AddTorrentActivity.TAG_RESULT_TORRENT)) {
                Torrent torrent = data.getParcelableExtra(AddTorrentActivity.TAG_RESULT_TORRENT);
                if (torrent != null) {
                    ArrayList<Torrent> list = new ArrayList<>();
                    list.add(torrent);
                    addTorrentsRequest(list);
                }
            }
        }
        break;
    }
}

From source file:org.nypl.simplified.app.MainSettingsAccountActivity.java

@Override
protected void onCreate(final @Nullable Bundle state) {
    super.onCreate(state);

    final Bundle extras = getIntent().getExtras();
    if (extras != null) {
        this.account = new AccountsRegistry(this).getAccount(extras.getInt("selected_account"));
    } else {//from w ww .j  a v a  2s . co m
        this.account = Simplified.getCurrentAccount();
    }

    final ActionBar bar = this.getActionBar();
    if (android.os.Build.VERSION.SDK_INT < 21) {
        bar.setDisplayHomeAsUpEnabled(false);
        bar.setHomeButtonEnabled(true);
        bar.setIcon(R.drawable.ic_arrow_back);
    } else {
        bar.setHomeAsUpIndicator(R.drawable.ic_arrow_back);
        bar.setDisplayHomeAsUpEnabled(true);
        bar.setHomeButtonEnabled(false);
    }

    final DocumentStoreType docs = Simplified.getDocumentStore(this.account, getResources());

    final LayoutInflater inflater = NullCheck.notNull(this.getLayoutInflater());

    final FrameLayout content_area = this.getContentFrame();
    final ViewGroup layout = NullCheck
            .notNull((ViewGroup) inflater.inflate(R.layout.settings_account, content_area, false));
    content_area.addView(layout);
    content_area.requestLayout();

    final TextView in_barcode_label = NullCheck.notNull(this.findViewById(R.id.settings_barcode_label));
    final TextView in_barcode_text = NullCheck.notNull(this.findViewById(R.id.settings_barcode_text));
    final TextView in_pin_label = NullCheck.notNull(this.findViewById(R.id.settings_pin_label));
    final ImageView in_barcode_image = NullCheck.notNull(this.findViewById(R.id.settings_barcode_image));
    final TextView in_barcode_image_toggle = NullCheck
            .notNull(this.findViewById(R.id.settings_barcode_toggle_barcode));
    final TextView in_pin_text = NullCheck.notNull(this.findViewById(R.id.settings_pin_text));
    final CheckBox in_pin_reveal = NullCheck.notNull(this.findViewById(R.id.settings_reveal_password));

    if (!this.account.pinRequired()) {
        in_pin_label.setVisibility(View.INVISIBLE);
        in_pin_text.setVisibility(View.INVISIBLE);
        in_pin_reveal.setVisibility(View.INVISIBLE);
    }

    final Button in_login = NullCheck.notNull(this.findViewById(R.id.settings_login));
    final Button in_signup = NullCheck.notNull(this.findViewById(R.id.settings_signup));

    this.sync_switch = findViewById(R.id.sync_switch);
    this.sync_table_row = findViewById(R.id.sync_table_row);
    this.sync_table_row.setVisibility(View.GONE);
    this.advanced_table_row = findViewById(R.id.link_advanced);
    this.advanced_table_row.setVisibility(View.GONE);

    this.advanced_table_row.setOnClickListener(view -> {
        final FragmentManager mgr = getFragmentManager();
        final FragmentTransaction transaction = mgr.beginTransaction();
        final SettingsAccountAdvancedFragment fragment = new SettingsAccountAdvancedFragment();
        transaction.add(R.id.settings_account_container, fragment).addToBackStack("advanced").commit();
    });

    final TableRow in_privacy = findViewById(R.id.link_privacy);
    final TableRow in_license = findViewById(R.id.link_license);

    final TextView account_name = NullCheck.notNull(this.findViewById(android.R.id.text1));
    final TextView account_subtitle = NullCheck.notNull(this.findViewById(android.R.id.text2));

    final ImageView in_account_icon = NullCheck.notNull(this.findViewById(R.id.account_icon));

    in_pin_text.setTransformationMethod(PasswordTransformationMethod.getInstance());
    if (android.os.Build.VERSION.SDK_INT >= 21) {
        this.handle_pin_reveal(in_pin_text, in_pin_reveal);
    } else {
        in_pin_reveal.setVisibility(View.GONE);
    }

    final TableRow in_report_issue = findViewById(R.id.report_issue);

    if (this.account.getSupportEmail() == null) {
        in_report_issue.setVisibility(View.GONE);
    } else {
        in_report_issue.setVisibility(View.VISIBLE);
        in_report_issue.setOnClickListener(view -> {
            final Intent intent = new Intent(this, ReportIssueActivity.class);
            final Bundle b = new Bundle();
            b.putInt("selected_account", this.account.getId());
            intent.putExtras(b);
            startActivity(intent);
        });
    }

    final TableRow in_support_center = findViewById(R.id.support_center);
    if (this.account.supportsHelpCenter()) {
        in_support_center.setVisibility(View.VISIBLE);
        in_support_center.setOnClickListener(view -> {
            final HSHelpStack stack = HSHelpStack.getInstance(this);
            final HSDeskGear gear = new HSDeskGear("https://nypl.desk.com/", "4GBRmMv8ZKG8fGehhA", null);
            stack.setGear(gear);
            stack.showHelp(this);
        });
    } else {
        in_support_center.setVisibility(View.GONE);
    }

    //Get labels from the current authentication document.
    final AuthenticationDocumentType auth_doc = docs.getAuthenticationDocument();
    in_barcode_label.setText(auth_doc.getLabelLoginUserID());
    in_pin_label.setText(auth_doc.getLabelLoginPassword());

    final TableLayout in_table_with_code = NullCheck
            .notNull(this.findViewById(R.id.settings_login_table_with_code));
    in_table_with_code.setVisibility(View.GONE);
    final TableLayout in_table_signup = NullCheck.notNull(this.findViewById(R.id.settings_signup_table));

    //    boolean locationpermission = false;
    //    if (ContextCompat.checkSelfPermission(getApplicationContext(), android.Manifest.permission.ACCESS_FINE_LOCATION) == PackageManager.PERMISSION_GRANTED) {
    //      locationpermission = true;
    //    }
    //    else
    //    {
    //      ActivityCompat.requestPermissions(this, new String[]{Manifest.permission.ACCESS_FINE_LOCATION}, 1);
    //    }

    if (this.account.supportsCardCreator() || this.account.getCardCreatorUrl() != null) {
        in_table_signup.setVisibility(View.VISIBLE);
    } else {
        in_table_signup.setVisibility(View.GONE);
    }

    in_login.setOnClickListener(v -> this.onLoginWithBarcode());

    final CheckBox in_age13_checkbox = NullCheck.notNull(this.findViewById(R.id.age13_checkbox));

    if (Simplified.getSharedPrefs().contains("age13")) {
        in_age13_checkbox.setChecked(Simplified.getSharedPrefs().getBoolean("age13"));
    } else if (account.getId() == 2) {
        showAgeGateOptionsDialog(in_age13_checkbox);
    }

    in_age13_checkbox.setOnCheckedChangeListener(this::showAgeChangeConfirmation);

    if (this.account.needsAuth()) {
        in_login.setVisibility(View.VISIBLE);
        in_age13_checkbox.setVisibility(View.GONE);
    } else {
        in_login.setVisibility(View.GONE);
        in_age13_checkbox.setVisibility(View.VISIBLE);
    }

    if (this.account.supportsCardCreator()) {
        in_signup.setOnClickListener(v -> {
            final Intent cardcreator = new Intent(this, CardCreatorActivity.class);
            startActivity(cardcreator);
        });
        in_signup.setText(R.string.need_card_button);

    } else if (this.account.getCardCreatorUrl() != null) {
        in_signup.setOnClickListener(v -> {
            final Intent e_card = new Intent(Intent.ACTION_VIEW);
            e_card.setData(Uri.parse(this.account.getCardCreatorUrl()));
            startActivity(e_card);
        });
        in_signup.setText(R.string.need_card_button);
    }

    final boolean permission = Simplified.getSharedPrefs().getBoolean("syncPermissionGranted",
            this.account.getId());
    this.sync_switch.setChecked(permission);

    /*
    If switching on, disable user interaction until server has responded.
    If switching off, disable applicable network requests by updating shared prefs flags.
     */
    this.sync_switch.setOnCheckedChangeListener((buttonView, isChecked) -> {
        if (isChecked) {
            buttonView.setEnabled(false);
            annotationsManager.updateServerSyncPermissionStatus(true, (success) -> {
                if (success) {
                    Simplified.getSharedPrefs().putBoolean("syncPermissionGranted", this.account.getId(), true);
                    this.sync_switch.setChecked(true);
                } else {
                    Simplified.getSharedPrefs().putBoolean("syncPermissionGranted", this.account.getId(),
                            false);
                    this.sync_switch.setChecked(false);
                }
                this.sync_switch.setEnabled(true);
                return kotlin.Unit.INSTANCE;
            });
        } else {
            Simplified.getSharedPrefs().putBoolean("syncPermissionGranted", this.account.getId(), false);
            this.sync_switch.setChecked(false);
        }
    });

    if (this.account.getPrivacyPolicy() != null) {
        in_privacy.setVisibility(View.VISIBLE);
    } else {
        in_privacy.setVisibility(View.GONE);
    }
    if (this.account.getContentLicense() != null) {
        in_license.setVisibility(View.VISIBLE);
    } else {
        in_license.setVisibility(View.GONE);
    }

    in_license.setOnClickListener(view -> {
        final Intent intent = new Intent(this, WebViewActivity.class);
        final Bundle b = new Bundle();
        WebViewActivity.setActivityArguments(b, this.account.getContentLicense(), "Content Licenses",
                SimplifiedPart.PART_SETTINGS);
        intent.putExtras(b);
        intent.setFlags(Intent.FLAG_ACTIVITY_NO_ANIMATION);
        startActivity(intent);
    });

    in_privacy.setOnClickListener(view -> {
        final Intent intent = new Intent(this, WebViewActivity.class);
        final Bundle b = new Bundle();
        WebViewActivity.setActivityArguments(b, this.account.getPrivacyPolicy(), "Privacy Policy",
                SimplifiedPart.PART_SETTINGS);
        intent.putExtras(b);
        intent.setFlags(Intent.FLAG_ACTIVITY_NO_ANIMATION);
        startActivity(intent);
    });

    this.navigationDrawerSetActionBarTitle();

    this.account_name_text = account_name;
    this.account_subtitle_text = account_subtitle;
    this.account_icon = in_account_icon;
    this.barcode_text = in_barcode_text;
    this.pin_text = in_pin_text;
    this.barcode_image_toggle = in_barcode_image_toggle;
    this.barcode_image = in_barcode_image;
    this.login = in_login;
    this.table_with_code = in_table_with_code;
    this.table_signup = in_table_signup;

    final CheckBox in_eula_checkbox = NullCheck.notNull(this.findViewById(R.id.eula_checkbox));

    final OptionType<EULAType> eula_opt = docs.getEULA();

    if (eula_opt.isSome()) {
        final Some<EULAType> some_eula = (Some<EULAType>) eula_opt;
        final EULAType eula = some_eula.get();

        in_eula_checkbox.setChecked(eula.eulaHasAgreed());
        in_eula_checkbox.setEnabled(true);
        in_eula_checkbox.setOnCheckedChangeListener((button, checked) -> eula.eulaSetHasAgreed(checked));

        if (eula.eulaHasAgreed()) {
            LOG.debug("EULA: agreed");
        } else {
            LOG.debug("EULA: not agreed");
        }
    } else {
        LOG.debug("EULA: unavailable");
    }

    this.getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN);
}

From source file:com.cloudbees.gasp.activity.PlacesDetailActivity.java

private void addGaspFragments() {
    FragmentManager fm = getFragmentManager();
    FragmentTransaction ft = fm.beginTransaction();

    mGaspDatabaseFragment = new GaspDatabaseFragment();
    mGaspRestaurantFragment = new GaspRestaurantFragment() {
        @Override/*from  w  w w .  j  ava 2  s  .  c  o m*/
        public void onSuccess(String location) {
            Log.d(TAG, "Gasp! restaurant added: " + location);
            mGaspRestaurantId = Integer.valueOf(location.substring(location.lastIndexOf("/") + 1));
            mGaspRestaurant = true;
            setButtons();
        }

        @Override
        public void onFailure() {
            Log.e(TAG, "Error adding Gasp! review");
        }
    };
    mGaspReviewFragment = new GaspReviewFragment() {
        @Override
        public void onSuccess(String location) {
            Log.d(TAG, "Gasp! review added: " + location);
        }

        @Override
        public void onFailure() {
            Log.e(TAG, "Error adding Gasp! review");
        }
    };

    ft.add(mGaspDatabaseFragment, getString(R.string.fragment_gasp_database));
    ft.add(mGaspRestaurantFragment, getString(R.string.fragment_gasp_restaurant));
    ft.add(mGaspReviewFragment, getString(R.string.fragment_gasp_review));

    ft.commit();
}

From source file:com.android.contacts.activities.DialtactsActivity.java

/**
 * Add search fragment.  Note this is called during onLayout, so there's some restrictions,
 * such as executePendingTransaction can't be used in it.
 *//*  w  w  w . j av  a 2  s  .  co  m*/
private void addSearchFragment() {
    // In order to take full advantage of "fragment deferred start", we need to create the
    // search fragment after all other fragments are created.
    // The other fragments are created by the ViewPager on the first onMeasure().
    // We use the first onLayout call, which is after onMeasure().

    // Just return if the fragment is already created, which happens after configuration
    // changes.
    if (mSearchFragment != null)
        return;

    final FragmentTransaction ft = getFragmentManager().beginTransaction();
    final Fragment searchFragment = new PhoneNumberPickerFragment();

    searchFragment.setUserVisibleHint(false);
    ft.add(R.id.dialtacts_frame, searchFragment);
    ft.hide(searchFragment);
    ft.commitAllowingStateLoss();
}

From source file:com.mainpanel.LifeApp_Map.java

private void initiateFragments() {
    Log.d("datastore", "initiateFragments");
    FragmentTransaction fragmentTransaction = mFragmentManager.beginTransaction();

    // Check to see if we have retained the fragment which handles
    // asynchronous backend calls
    mProcessingFragment = (CloudBackendFragment) mFragmentManager.findFragmentByTag(PROCESSING_FRAGMENT_TAG);
    // If not retained (or first time running), create a new one
    if (mProcessingFragment == null) {
        mProcessingFragment = new CloudBackendFragment();
        mProcessingFragment.setRetainInstance(true);
        fragmentTransaction.add(mProcessingFragment, PROCESSING_FRAGMENT_TAG);
    }/* ww  w  .  j  a  v a2s  .  c om*/
    fragmentTransaction.commit();
}