Android is based on intent to implement data transfer between activity _android

Source: Internet
Author: User
Tags sqlite database

The example in this article describes the way Android implements data transfer between activity based on intent. Share to everyone for your reference, specific as follows:


Package Com.test.intentdemo;
Import android.content.Intent;
Import Android.os.Bundle;
Import Android.view.Menu;
Import Android.view.View;
Import Android.widget.Button;
  public class Mainactivity extends activity {private Button btn=null; The public void OnCreate (Bundle savedinstancestate)//oncreate method is used to initialize the activity instance object {super.oncreate (savedinstancestate); The role of/super.oncreate (Savedinstancestate) is to invoke the OnCreate method of its parent activity to achieve drawing work on the interface Setcontentview (r.layout.activity_
    Main); The function of//setcontentview (R.layout.main) is to load an interface btn= (Button) Findviewbyid (R.ID.BTN);
  Btn.setonclicklistener (listener);
    Private View.onclicklistener listener=new View.onclicklistener () {@Override public void OnClick (View v) {//Intent intent=new Intent ();//Intent.setaction (intent.action_sendto);//Intent.setdata (Uri.parse ("Smst
o:5554 ")); Intent.putextra ("Sms_body", "hello!"); /sms_body can not be freely replaced by//startactivity (intENT);
      Intent intent=new Intent (); Intent.setclass (Mainactivity.this, Secondactivity.class)//jump from one activity to another activity Intent.putextra ("str", "
    Intent demo ")//Add additional data to Intent, key is" str ", key value is" Intent Demo "startactivity (Intent);
    @Override public boolean Oncreateoptionsmenu (Menu menu) {getmenuinflater (). Inflate (, menu);
  return true;



Package Com.test.intentdemo;
Import Android. r.string;
Import android.content.Intent;
Import Android.os.Bundle;
Import Android.widget.TextView;
public class Secondactivity extends activity
  private TextView secondtxt;
  protected void onCreate (Bundle savedinstancestate)
    //TODO auto-generated method stub
    super.oncreate (savedinstancestate);
    Setcontentview (R.layout.second);
    Intent intent=getintent ()//getintent retrieves the original Intent contained in the project, assigns the retrieved Intent to a variable of Intent type Intent Bundle
    Intent.getextras ();//.getextras () gets additional data
    String str=bundle.getstring ("str") attached to intent;//getstring () Returns the value of the specified key
    secondtxt= (TextView) Findviewbyid (;//TextView Display value
    secondtxt.settext (str);

For more information on Android-related content readers can view the site: "The activity of Android programming skills Summary", "Android Development introduction and Advanced Course", "Android Resource Operation skills Summary", "Android File operating skills summary" , "Android Operation SQLite Database Skills Summary", "Android operation JSON format Data Skills summary", "Android Database Operation skills Summary", "Android programming development of SD card operation method Summary", " Android View tips Summary and a summary of the use of Android controls

I hope this article will help you with the Android program.

Related Article

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: 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.