Android delivers data via application

Source: Internet
Author: User

</pre><pre>
Package Com.example.applicationtest;import android.app.application;/** * Created to Chang on 14-10-1. */public class App extends application {public    String getName () {        return name;    }    public void SetName (String name) {        this.name = name;    }    public String name;    @Override public    void OnCreate () {        super.oncreate ();        SetName ("Zhang San");}    }
Package Com.example.applicationtest;import Android.app.activity;import Android.content.intent;import Android.os.bundle;import Android.view.view;import Android.widget.button;public class MyActivity extends Activity {    private Button btnlaunch = null;    Private App myApp;    /**     * Called when the activity is first created.     *    /@Override public    void OnCreate (Bundle savedinstancestate) {        super.oncreate (savedinstancestate);        Setcontentview (r.layout.main);        Btnlaunch = (Button) This.findviewbyid (r.id.btnlaunch);        MYAPP = (App) this.getapplication ();        Myapp.setname ("Hello");        Btnlaunch.setonclicklistener (New View.onclicklistener () {            @Override public            void OnClick (view view) {                Intent Intent = new Intent (myactivity.this,otheractivity.class);                StartActivity (intent);}}        );}    }

Package Com.example.applicationtest;import Android.app.activity;import Android.os.bundle;import android.widget.textview;/** * Created by Chang on 14-10-1. */public class Otheractivity extends Activity {    private App myApp;    Private TextView TextView;    @Override    protected void onCreate (Bundle savedinstancestate) {        super.oncreate (savedinstancestate);        Setcontentview (r.layout.other);        TextView = (TextView) Findviewbyid (r.id.showmsg);        MYAPP = (App) getapplication ();        Textview.settext (Myapp.getname ());}    }

<?xml version= "1.0" encoding= "Utf-8"? ><manifest xmlns:android= "http://schemas.android.com/apk/res/ Android "          package=" com.example.ApplicationTest "          android:versioncode=" 1 "          android:versionname=" 1.0 " >    <uses-sdk android:minsdkversion= "/>    <application android:label="            @string/app_name "            android:icon= "@drawable/ic_launcher"            android:name= ". App >        <activity                android:name= "myactivity"                android:label= "@string/app_name" >            < intent-filter>                <action android:name= "Android.intent.action.MAIN"/>                <category android:name= "Android.intent.category.LAUNCHER"/>            </intent-filter>        </activity>        <activity Android:name= ". Otheractivity ">        </activity>    </application></manifest>



Android passes data via application

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.