Use SharedPreferences to remember the user name and password.
<Span style = "font-family: Arial, Helvetica, sans-serif; font-size: 12px; background-color: rgb (255,255,255 ); "> SharedPreferences is actually a class in which the operating program writes data to external storage and reads data. Data exists in XML format. </Span>
SharedPreferences data operation modes
- Context. MODE_PRIVATE
- Context. MODE_APPEND
- Context. MODE_WORLD_READABLE
- Context. MODE_WORLD_WRITEABLE
Context. MODE_PRIVATE: the default operation mode. This mode indicates that the file is private data and can only be accessed by the application itself. In this mode, the written content overwrites the Context of the original file. MODE_APPEND: the mode checks whether the file exists and appends content to the file if it exists. Otherwise, a new file is created. context. MODE_WORLD_READABLE and Context. MODE_WORLD_WRITEABLE is used to control whether other applications have the permission to read and write the file. MODE_WORLD_READABLE: indicates that the current file can be read by other applications. MODE_WORLD_WRITEABLE: indicates that the current file can be written by other applications.
Import android. app. activity; import android. content. sharedPreferences; import android. content. sharedPreferences. editor; import android. OS. bundle; import android. widget. toast; public class MainActivity extends Activity {@ Override protected void onCreate (Bundle savedInstanceState) {super. onCreate (savedInstanceState); setContentView (R. layout. activity_main); SharedPreferences sp = getSharedPreferences ("bee ", MODE_PRIVATE); // bee indicates the name of the generated xml, and MODE_PRIVATE indicates the private mode. Editor editor = sp. edit (); // get the editor, and then add the data editor. putString ("username", "eric"); editor. putString ("passws", "lzw213"); editor. commit (); // submit data // obtain data String result = sp. getString ("username", "error"); Toast. makeText (this, result, 0 ). show ();}}