Java tutorial
/* * Copyright (C) 2012 Jamie Nicol <jamie@thenicols.net> * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. */ package org.jamienicol.episodes; import android.content.Intent; import android.os.Bundle; import android.support.v4.app.FragmentTransaction; import android.support.v7.app.AppCompatActivity; import android.view.MenuItem; import android.view.Window; public class AddShowSearchActivity extends AppCompatActivity { @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); supportRequestWindowFeature(Window.FEATURE_INDETERMINATE_PROGRESS); setContentView(R.layout.add_show_search_activity); getSupportActionBar().setDisplayHomeAsUpEnabled(true); Intent intent = getIntent(); String query = intent.getStringExtra("query"); getSupportActionBar().setTitle(query); // create and add search fragment, // but only on the first time the activity is created if (savedInstanceState == null) { AddShowSearchFragment fragment = AddShowSearchFragment.newInstance(query); FragmentTransaction transaction = getSupportFragmentManager().beginTransaction(); transaction.add(R.id.search_fragment_container, fragment); transaction.commit(); } } @Override public boolean onOptionsItemSelected(MenuItem item) { switch (item.getItemId()) { case android.R.id.home: Intent intent = new Intent(this, MainActivity.class); intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_NEW_TASK); startActivity(intent); finish(); return true; default: return super.onOptionsItemSelected(item); } } }