1. Original interface
PackageCom.fish.helloworld;Importandroid.app.Activity;Importandroid.content.Intent;ImportAndroid.os.Bundle;ImportAndroid.view.Menu;ImportAndroid.view.MenuItem;ImportAndroid.view.View;ImportAndroid.view.View.OnClickListener;ImportAndroid.widget.Button; Public classForwardingextendsActivity {PrivateBackbutton_onclicklistener Backbuttonlistener =NewBackbutton_onclicklistener (); classBackbutton_onclicklistenerImplementsonclicklistener{ Public voidOnClick (View v) {Intent Intent=NewIntent (); Intent.setclass (Forwarding. This, Mainactivity.class); StartActivity (Intent); Finish (); }} @Overrideprotected voidonCreate (Bundle savedinstancestate) {Super. OnCreate (savedinstancestate); Setcontentview (r.layout.activity_forwarding); FinalButton Backbutton =(Button) Findviewbyid (R.id.button1); Backbutton.setonclicklistener (Backbuttonlistener); } @Override Public BooleanOncreateoptionsmenu (Menu menu) {//inflate the menu; This adds items to the action bar if it is present.getmenuinflater (). Inflate (r.menu.forwarding, menu); return true; } @Override Public Booleanonoptionsitemselected (MenuItem item) {//Handle Action Bar item clicks here. The Action Bar would//automatically handle clicks on the Home/up button, so long//As you specify a the parent activity in Androidmanifest.xml. intID =Item.getitemid (); if(id = =r.id.action_settings) { return true; } return Super. onoptionsitemselected (item); }}
2, Androidmanifest.xml
<?XML version= "1.0" encoding= "Utf-8"?><Manifestxmlns:android= "Http://schemas.android.com/apk/res/android" Package= "Com.fish.helloworld"Android:versioncode= "1"Android:versionname= "1.0" > <USES-SDKandroid:minsdkversion= "+"android:targetsdkversion= "+" /> <ApplicationAndroid:allowbackup= "true"Android:icon= "@drawable/ic_launcher"Android:label= "@string/app_name"Android:theme= "@style/apptheme" > <ActivityAndroid:name=". Mainactivity "Android:label= "@string/app_name" > </Activity> <ActivityAndroid:name=". Forwarding "Android:label= "@string/title_activity_forwarding" > <Intent-filter> <ActionAndroid:name= "Android.intent.action.MAIN" /> <categoryAndroid:name= "Android.intent.category.LAUNCHER" /> </Intent-filter> </Activity> </Application></Manifest>
3.