Java tutorial
/* * Copyright 2014-2015 Amazon.com, Inc. or its affiliates. All Rights Reserved. * * Licensed under the Apache License, Version 2.0 (the "License"). * You may not use this file except in compliance with the License. * A copy of the License is located at * * http://aws.amazon.com/apache2.0 * * or in the "license" file accompanying this file. This file is distributed * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either * express or implied. See the License for the specific language governing * permissions and limitations under the License. */ package com.amazonaws.devicefarm.android.referenceapp.Activities; import android.content.Intent; import android.os.Bundle; import android.support.v4.app.NavUtils; import android.support.v7.app.AppCompatActivity; import android.support.v7.widget.Toolbar; import android.view.MenuItem; import android.widget.TextView; import com.amazonaws.devicefarm.android.referenceapp.R; import butterknife.ButterKnife; import butterknife.InjectView; import butterknife.OnClick; /** * <h1>Up Navigation Activity</h1> * <p> * An activity demonstating Up navigation * </p> */ public class UpNavigationActivity extends AppCompatActivity { @InjectView(R.id.toolbar) Toolbar toolbar; @InjectView(R.id.toolbar_title) TextView toolbarTitle; @Override protected void onCreate(final Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.up_navigation); ButterKnife.inject(this); setSupportActionBar(toolbar); getSupportActionBar().setDisplayHomeAsUpEnabled(true); getSupportActionBar().setDisplayShowTitleEnabled(false); toolbarTitle.setText(getString(R.string.first_level)); } /** * Support for the back hardware button */ @Override public boolean onOptionsItemSelected(final MenuItem item) { if (item.getItemId() == android.R.id.home) { Intent intent = new Intent(getApplication(), MainActivity.class); intent.addFlags(Intent.FLAG_ACTIVITY_NO_ANIMATION); NavUtils.navigateUpTo(this, intent); return true; } return super.onOptionsItemSelected(item); } /** * Pushes up to the next class */ @OnClick(R.id.nested_up_button) public void onNextButton() { startActivity(new Intent(this, UpNavigationContent.class)); } }