This article describes the method of Android implementing data transfer between activities based on Intent. Share it for your reference, as follows:
MainActivity:
package ; import ; import ; import ; import ; import ; import ; import ; public class MainActivity extends Activity { private Button btn=null; public void onCreate(Bundle savedInstanceState)//The onCreate method is used to initialize the Activity instance object { (savedInstanceState);//(savedInstanceState) is to call the onCreate method of its parent class Activity to realize the drawing work of the interface setContentView(.activity_main);//The function of setContentView() is to load an interface btn=(Button)findViewById(); (listener); } private listener=new () { @Override public void onClick(View v) { // Intent intent=new Intent(); // (Intent.ACTION_SENDTO); // (("smsto:5554")); // ("sms_body", "Hello!");//sms_body cannot be replaced at will// startActivity(intent); Intent intent=new Intent(); (, );//Skip from one activity to another activity ("str", "Intent Demo");//Add extra data to the intent, the key is "str", and the key value is "Intent Demo" startActivity(intent); } }; @Override public boolean onCreateOptionsMenu(Menu menu) { getMenuInflater().inflate(.activity_main, menu); return true; } }
secondAcitivity:
package ; import ; import ; import ; import ; import ; public class SecondActivity extends Activity { private TextView secondTxt; @Override protected void onCreate(Bundle savedInstanceState) { // TODO Auto-generated method stub (savedInstanceState); setContentView(); Intent intent=getIntent();//getIntent retrieves the original intent contained in the project and assigns the retrieved intent to a variable of Intent of type intent Bundle bundle=();//.getExtras() gets the extra data attached to the intent String str=("str");//getString() returns the value of the specified key secondTxt=(TextView)findViewById();// Use TextView to display the value (str); } }
For more information about Android related content, please check out the topic of this site:Android programming activity operation skills summary》、《Android development introduction and advanced tutorial》、《Android resource operation skills summary》、《Android file operation skills summary》、《Summary of Android's SQLite database skills》、《Summary of Android data skills for operating json format》、《Android database operation skills summary》、《A summary of SD card operation methods for Android programming and development》、《Android View View Tips Summary"and"Android control usage summary》
I hope this article will be helpful to everyone's Android programming design.