1, the first learning activities and intentions, the interaction between activities. Pass the data and accept the result.
Attach one of the simplest examples
In this simple to no simpler case, the most important files are the Usingintentactivity.java and Secondactivity.java files and the androidmanifest configuration file.
Attach a simple code
Packagecom.example.usingintent;Importandroid.support.v7.app.ActionBarActivity;ImportAndroid.os.Bundle;ImportAndroid.view.Menu;ImportAndroid.view.MenuItem;ImportAndroid.view.View;Importandroid.content.Intent; Public classUsingintentactivityextendsactionbaractivity {@Overrideprotected voidonCreate (Bundle savedinstancestate) {Super. OnCreate (savedinstancestate); Setcontentview (R.layout.main); } @Override Public BooleanOncreateoptionsmenu (Menu menu) {//inflate the menu; This adds items to the action bar if it is present.getmenuinflater (). Inflate (r.menu.using_intent, 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); } Public voidOnClick (view view) {startactivity (NewIntent ("Com.example.usingintent.SecondActivity")); }}
Package com.example.usingintent; Import android.app.Activity; Import Android.os.Bundle; Public class extends activity{ @Override publicvoid onCreate (Bundle savedinstancestate) { super. OnCreate (savedinstancestate); Setcontentview (r.layout.secondactivity); }}
<?xml version= "1.0" encoding= "Utf-8"? ><manifest xmlns:android= "Http://schemas.android.com/apk/res/android" Package= "Com.example.usingintent"Android:versioncode= "1"Android:versionname= "1.0" > <uses-SDK Android:minsdkversion= "8"android:targetsdkversion= "/>" <Application Android:allowbackup= "true"Android:icon= "@drawable/ic_launcher"Android:label= "@string/app_name"Android:theme= "@style/apptheme" > <Activity Android:name=". Usingintentactivity "Android:label= "@string/app_name" > <intent-filter> <action android:name= "Android.intent.action.MA In "/> <category android:name=" Android.intent.category.LAUNCHER "/> </intent-filter& Gt </activity> <Activity Android:name=". Secondactivity "Android:label= "Second Activity" > <intent-filter> <action android:name= "Com.example.usingintent.s Econdactivity "/> <category android:name=" Android.intent.category.DEFAULT "/> </inte Nt-filter> </activity> </application></manifest>
Pay attention to the wording of the activity's package.
Android Learning Program