1. Introduce
For beginners The data transmission between different activity of Android is always a difficult problem, the main solution is to use bundle to transmit data, one is to use sharedpreferences. The difference between the two, generally speaking, sharedpreferences is used to store lightweight data, stored in XML, and can be persisted. Anti-bundle can transmit a lot of data, but it doesn't last.
2. The concrete realization Method Bundle
In sender class A
Bundle Bundle = new Bundle ();
Saves the input information
bundle.putstring ("String Name", "String Transmitted");
Intent intent=new Intent (a.this,b.class);
Intent.putextras (bundle);
In receiver class B
Bundle b=getintent (). Getextras ();
Gets the bundle information
string info=b.getstring ("string name");
Note: string names are the same
Sharedpreferences
Sharedpreferences usage is simple, if you want to edit the content in Sharedpreferences, you need to use the editor object.
In the issue of party a
Sharedpreferences sp = preferencemanager.getdefaultsharedpreferences (GetContext ());
Editor Editor = Sp.edit ();
Editor.putstring ("String variable name", "string content issued");
Editor.commit ();
Receiving Party B
Sharedpreferences sp = preferencemanager.getdefaultsharedpreferences (b.this);
String grade = Sp.getstring ("String variable name", "Default value");
See more highlights of this column: http://www.bianceng.cnhttp://www.bianceng.cn/OS/extra/