Android Learning Program

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.