Example usage for android.app FragmentManager findFragmentById

List of usage examples for android.app FragmentManager findFragmentById

Introduction

In this page you can find the example usage for android.app FragmentManager findFragmentById.

Prototype

public abstract Fragment findFragmentById(int id);

Source Link

Document

Finds a fragment that was identified by the given id either when inflated from XML or as the container ID when added in a transaction.

Usage

From source file:com.bernard.beaconportal.activities.activity.MessageList.java

/**
 * Get references to existing fragments if the activity was restarted.
 *//* www. j a va2s .  c om*/
private void findFragments() {
    FragmentManager fragmentManager = getFragmentManager();
    mMessageListFragment = (MessageListFragment) fragmentManager.findFragmentById(R.id.message_list_container);
    mMessageViewFragment = (MessageViewFragment) fragmentManager.findFragmentById(R.id.message_view_container);
}

From source file:de.anderdonau.spacetrader.Main.java

@SuppressWarnings("ConstantConditions")
@Override/*  www  . j  a v a2  s  .c  o  m*/
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    mContext = getApplicationContext();

    SharedPreferences sp = getSharedPreferences("spacetrader", MODE_PRIVATE);
    String theme = sp.getString("Theme", "Light");
    if ("Light".equals(theme)) {
        setTheme(R.style.AppTheme_Light);
    } else {
        setTheme(R.style.AppTheme);
    }

    setContentView(R.layout.activity_welcome_screen);
    FragmentManager fragmentManager = getFragmentManager();

    // Set up the drawer.
    DrawerLayout drawer_layout = (DrawerLayout) findViewById(R.id.drawer_layout);
    mNavigationDrawerFragment = (NavigationDrawerFragment) fragmentManager
            .findFragmentById(R.id.navigation_drawer);
    mNavigationDrawerFragment.setUp(R.id.navigation_drawer, drawer_layout);
    fragmentManager.beginTransaction().hide(mNavigationDrawerFragment).commit();

    populateBitmaps();
    boolean gameLoaded = false;

    try {
        File path = new File(Environment.getExternalStorageDirectory().toString() + "/SpaceTrader");
        File f = new File(path, "savegame.txt");
        FileInputStream fis = new FileInputStream(f);
        ObjectInputStream ois = new ObjectInputStream(fis);
        SaveGame_v110 s = (SaveGame_v110) ois.readObject();
        gameState = new GameState(s);
        GameState.isValid = true;
        gameLoaded = true;
        ois.close();
        fis.close();
        changeFragment(FRAGMENTS.SYSTEM_INFORMATION);
    } catch (Exception ignored) {
    }

    if (!gameLoaded) {
        try {
            File path = new File(Environment.getExternalStorageDirectory().toString() + "/SpaceTrader");
            File f = new File(path, "savegame.txt");
            FileInputStream fis = new FileInputStream(f);
            ObjectInputStream ois = new ObjectInputStream(fis);
            SaveGame_v111 s = (SaveGame_v111) ois.readObject();
            gameState = new GameState(s);
            GameState.isValid = true;
            gameLoaded = true;
            ois.close();
            fis.close();
            changeFragment(FRAGMENTS.SYSTEM_INFORMATION);
        } catch (Exception ignored) {
        }
    }

    if (!gameLoaded) {
        try {
            File path = new File(Environment.getExternalStorageDirectory().toString() + "/SpaceTrader");
            File f = new File(path, "savegame.txt");
            FileInputStream fis = new FileInputStream(f);
            ObjectInputStream ois = new ObjectInputStream(fis);
            SaveGame_v120 s = (SaveGame_v120) ois.readObject();
            gameState = new GameState(s);
            WarpSystem = gameState.SolarSystem[gameState.WarpSystem];
            GameState.isValid = true;
            gameLoaded = true;
            ois.close();
            fis.close();
            changeFragment(gameState.currentState);
        } catch (Exception ignored) {
        }
    }

    if (!gameLoaded) {
        gameState = new GameState(this, "Jameson");
        changeFragment(FRAGMENTS.NEW_GAME);
    }
}