List of usage examples for android.app FragmentTransaction addToBackStack
public abstract FragmentTransaction addToBackStack(@Nullable String name);
From source file:me.pzheng.conn.MainActivity.java
@Override public boolean onOptionsItemSelected(MenuItem item) { // Handle action bar item clicks here. The action bar will // automatically handle clicks on the Home/Up button, so long // as you specify a parent activity in AndroidManifest.xml. int id = item.getItemId(); //noinspection SimplifiableIfStatement if (id == R.id.action_settings) { FragmentManager fm = getFragmentManager(); FragmentTransaction transaction = fm.beginTransaction(); Fragment fragment;// ww w .j av a2s . co m fragment = fm.findFragmentByTag(SettingsFragment.TAG); if (fragment == null) { fragment = new SettingsFragment(); } transaction.replace(R.id.container, fragment, SettingsFragment.TAG); transaction.addToBackStack(null); transaction.commit(); return true; } return super.onOptionsItemSelected(item); }
From source file:com.example.sans.myapplication.Login.OnlineActivity.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_online); shares = getSharedPreferences("SHARES", 0); Fragment newFragment = new OnlineBotFragment(); FragmentTransaction transaction = getFragmentManager().beginTransaction(); transaction.replace(R.id.login_bot, newFragment); transaction.addToBackStack(null); transaction.commit();//from ww w . j a v a 2 s .com transaction = getFragmentManager().beginTransaction(); newFragment = new LoginTopFragment(); transaction.replace(R.id.login_top, newFragment); transaction.commit(); toolbar = (Toolbar) findViewById(R.id.toolbar); setSupportActionBar(toolbar); //Initializing NavigationView navigationView = (NavigationView) findViewById(R.id.navigation_view); //Setting Navigation View Item Selected Listener to handle the item click of the navigation menu header = navigationView.inflateHeaderView(R.layout.header); JSONObject driver_data = null; try { driver_data = new JSONObject(shares.getString("DRIVER_DATA", "ERROR")); } catch (JSONException e) { e.printStackTrace(); } TextView driver_name_header = (TextView) header.findViewById(R.id.username); TextView car_id_header = (TextView) header.findViewById(R.id.car_id); final ImageView pp_header = (ImageView) header.findViewById(R.id.profile_image); try { car_id_header.setText(driver_data.getString("license")); driver_name_header.setText(driver_data.getString("name")); Client client = new Client(); client.get(driver_data.getString("image"), new FileAsyncHttpResponseHandler(OnlineActivity.this.getApplicationContext()) { @Override public void onFailure(int i, Header[] headers, Throwable throwable, File file) { } @Override public void onSuccess(int statusCode, Header[] headers, final File response) { OnlineActivity.this.runOnUiThread(new Runnable() { @Override public void run() { Bitmap image = BitmapFactory.decodeFile(response.getPath()); pp_header.setImageBitmap(image); } }); } }); } catch (JSONException e) { e.printStackTrace(); } catch (NullPointerException e) { SharedPreferences.Editor editor = shares.edit(); final Client client1 = new Client(); RequestParams params1 = new RequestParams(); editor.putBoolean("ONLINE", false); editor.putBoolean("LOGIN", false); editor.commit(); Intent intent = getApplicationContext().getPackageManager() .getLaunchIntentForPackage(getApplicationContext().getPackageName()); intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); startActivity(intent); } header.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { Intent i = new Intent(OnlineActivity.this, MenuItemActivity.class); i.putExtra("MENU_ITEM", 0); OnlineActivity.this.startActivity(i); drawerLayout.closeDrawers(); } }); navigationView.setNavigationItemSelectedListener(new NavigationView.OnNavigationItemSelectedListener() { // This method will trigger on item Click of navigation menu @Override public boolean onNavigationItemSelected(MenuItem menuItem) { //Checking if the item is in checked state or not, if not make it in checked state nav = true; menuItem.setChecked(false); //Closing drawer on item click drawerLayout.closeDrawers(); FragmentManager fragmentManager = getFragmentManager(); FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction(); Fragment fragment; //Check to see which item was being clicked and perform appropriate action switch (menuItem.getItemId()) { case R.id.timetable: case R.id.service: case R.id.history: case R.id.mission: case R.id.points: case R.id.notice: Intent i = new Intent(OnlineActivity.this, MenuItemActivity.class); i.putExtra("MENU_ITEM", menuItem.getItemId()); OnlineActivity.this.startActivity(i); break; case R.id.login: Toast.makeText(getApplicationContext(), "Logout Selected", Toast.LENGTH_SHORT).show(); SharedPreferences.Editor editor = shares.edit(); final Client client = new Client(); RequestParams params = new RequestParams(); params.put("id", shares.getInt("ID", 0)); params.put("status", 999); client.post("driver/setStatus", params, new JsonHttpResponseHandler()); editor.putBoolean("ONLINE", false); editor.putBoolean("LOGIN", false); editor.commit(); Intent intent = getApplicationContext().getPackageManager() .getLaunchIntentForPackage(getApplicationContext().getPackageName()); intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); startActivity(intent); break; default: Toast.makeText(getApplicationContext(), "Somethings Wrong", Toast.LENGTH_SHORT).show(); break; } return false; } }); drawerLayout = (DrawerLayout) findViewById(R.id.drawer); ActionBarDrawerToggle actionBarDrawerToggle = new ActionBarDrawerToggle(this, drawerLayout, toolbar, R.string.openDrawer, R.string.closeDrawer) { @Override public void onDrawerClosed(View drawerView) { // Code here will be triggered once the drawer closes as we dont want anything to happen so we leave this blank super.onDrawerClosed(drawerView); drawerLayout.setSelected(false); } @Override public void onDrawerOpened(View drawerView) { // Code here will be triggered once the drawer open as we dont want anything to happen so we leave this blank super.onDrawerOpened(drawerView); } }; drawerLayout.setDrawerListener(actionBarDrawerToggle); actionBarDrawerToggle.syncState(); }
From source file:org.steveleach.scoresheet.ui.ScoresheetActivity.java
public void showFragment(Fragment fragment) { FragmentTransaction tx = getFragmentManager().beginTransaction(); tx.replace(R.id.fragmentContainer, fragment, MAIN_FRAGMENT); tx.addToBackStack(null); tx.commit();//from w ww. j a v a 2 s. c o m }
From source file:org.openaccessbutton.openaccessbutton.MainActivity.java
public void launchFragment(Fragment fragment, String tag, Bundle data, boolean backstack) { FragmentTransaction fragmentTransaction = getFragmentManager().beginTransaction(); fragmentTransaction.replace(R.id.content_frame, fragment, tag); if (backstack) { fragmentTransaction.addToBackStack(tag); }/*from www . ja va2 s .com*/ fragmentTransaction.commit(); }
From source file:com.classiqo.nativeandroid_32bitz.ui.MusicPlayerActivity.java
private void navigateToBrowser(String mediaId) { LogHelper.d(TAG, "navigateToBrowser, mediaId = " + mediaId); MediaBrowserFragment fragment = getBrowseFragment(); if (fragment == null || !TextUtils.equals(fragment.getMediaId(), mediaId)) { fragment = new MediaBrowserFragment(); fragment.setMediaId(mediaId);//from w w w. ja v a2s . c o m FragmentTransaction transaction = getFragmentManager().beginTransaction(); transaction.setCustomAnimations(R.animator.slide_in_from_right, R.animator.slide_out_to_left, R.animator.slide_in_from_left, R.animator.slide_out_to_right); transaction.replace(R.id.container, fragment, FRAGMENT_TAG); if (mediaId != null) { transaction.addToBackStack(null); } transaction.commit(); } }
From source file:cmput301.f13t01.readstory.ReadFragmentActivity.java
/** * displays screen specific help//from w ww . ja v a 2s. c o m */ private void onSelectHelp() { android.app.FragmentTransaction ft = getFragmentManager().beginTransaction(); android.app.Fragment prev = getFragmentManager().findFragmentByTag("help_dialog"); if (prev != null) { ft.remove(prev); } ft.addToBackStack(null); android.app.DialogFragment newFragment = (android.app.DialogFragment) HelpFragment .newInstance(HelpMessage.READ_STORY); newFragment.show(ft, "help_dialog"); }
From source file:com.spacejake.jake.ultimatepurduediner.MainActivity.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); mTitle = getTitle();/*w ww. j a v a2 s.co m*/ mNavigationDrawerFragment = (NavigationDrawerFragment) getFragmentManager() .findFragmentById(R.id.navigation_drawer); // Set up the drawer. mNavigationDrawerFragment.setUp(R.id.navigation_drawer, (DrawerLayout) findViewById(R.id.drawer_layout)); cal = Calendar.getInstance(); dateString = format.format(cal.getTime()); spinner = (Spinner) findViewById(R.id.spinner); spinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() { @Override public void onItemSelected(AdapterView<?> adapterView, View view, int i, long l) { updateMeal(); } @Override public void onNothingSelected(AdapterView<?> adapterView) { } }); listView = (ListView) findViewById(R.id.listview); listView.setOnItemClickListener(new AdapterView.OnItemClickListener() { @Override public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) { String foodName = adapterView.getItemAtPosition(i).toString(); String meal = spinner.getSelectedItem().toString(); FragmentTransaction ft = getFragmentManager().beginTransaction(); Fragment previous = getFragmentManager().findFragmentByTag("floatingFood"); if (previous != null) { ft.remove(previous); } ft.addToBackStack(null); DialogFragment frag = FloatingFood.newInstance(foodName, mTitle.toString(), meal, cal); frag.show(ft, "floatingFood"); } }); }
From source file:cmput301.f13t01.editstory.EditStoryActivity.java
private void onSelectHelp() { android.app.FragmentTransaction ft = getFragmentManager().beginTransaction(); android.app.Fragment prev = getFragmentManager().findFragmentByTag("help_dialog"); if (prev != null) { ft.remove(prev);/*from w ww. j av a 2 s . c o m*/ } ft.addToBackStack(null); android.app.DialogFragment newFragment = (android.app.DialogFragment) HelpFragment .newInstance(HelpMessage.EDIT_STORY); newFragment.show(ft, "help_dialog"); }
From source file:com.andreykaraman.multinote.ui.list.AltNoteActivity.java
public void onArticleSelected(int position, long id) { // The user selected the headline of an article from the // HeadlinesFragment // Capture the article fragment from the activity layout AltEditNoteFragment articleFrag = (AltEditNoteFragment) getFragmentManager() .findFragmentById(R.id.fragment_new_note); if (articleFrag != null) { // If article frag is available, we're in two-pane layout... // Call a method in the ArticleFragment to update its content articleFrag.updateArticleView(position); } else {//from w w w . j a va 2s . c o m // If the frag is not available, we're in the one-pane layout and // must swap frags... // Create fragment and give it an argument for the selected article AltEditNoteFragment newFragment = new AltEditNoteFragment(); Bundle args = new Bundle(); args.putLong(AltEditNoteFragment.ARG_ID, id); newFragment.setArguments(args); FragmentTransaction transaction = getFragmentManager().beginTransaction(); // Replace whatever is in the fragment_container view with this // fragment, // and add the transaction to the back stack so the user can // navigate back transaction.replace(R.id.fragment_container, newFragment); transaction.addToBackStack(null); // Commit the transaction transaction.commit(); } }
From source file:cmput301.f13t01.editstory.EditStoryActivity.java
/** * Display selection of fragment/*from ww w . j a v a 2 s . c o m*/ */ public void showFragmentSelection() { android.app.FragmentTransaction ft = getFragmentManager().beginTransaction(); android.app.Fragment prev = getFragmentManager().findFragmentByTag("choice_dialog"); if (prev != null) { ft.remove(prev); } ft.addToBackStack(null); android.app.DialogFragment newFragment = (android.app.DialogFragment) StoryFragmentListFragment .newInstance(); newFragment.show(ft, "choice_dialog"); }