赣州企业做网站,织梦网站安装视频教程,静态网站没有数据库吗,石家庄哪里能制作网站我有一个具有登录,注销功能的Android应用程序.登录表单包含用户名和密码以及登录按钮.我想在用户选中“记住我”复选框时保存用户名和密码.我的project.java文件如下所示#xff1a;public class project extends Activity {private static final int IO_BUFFER_SIZE 4 * 102…我有一个具有登录,注销功能的Android应用程序.登录表单包含用户名和密码以及登录按钮.我想在用户选中“记住我”复选框时保存用户名和密码.我的project.java文件如下所示public class project extends Activity {private static final int IO_BUFFER_SIZE 4 * 1024;/** Called when the activity is first created. */public int user_id,current_user_id;public String access_token,username,current_username;public boolean user_logged_infalse;public ProgressDialog progdialog;Overridepublic void onCreate(final Bundle savedInstanceState) {super.onCreate(savedInstanceState);progdialog new ProgressDialog(this);progdialog.setMessage(loading...);initLogin();}public void initLogin(){setContentView(R.layout.login);Button button (Button) findViewById(R.id.login_login);button.setOnClickListener(new View.OnClickListener(){public void onClick(View v) {login();}});}public void login(){try{String login_username(((EditText) findViewById(R.id.login_username)).getText()).toString();String login_password(((EditText) findViewById(R.id.login_password)).getText()).toString();List nameValuePairs new ArrayList(2);nameValuePairs.add(new BasicNameValuePair(username,login_username));nameValuePairs.add(new BasicNameValuePair(password,login_password));String contentpostUrlContent(api_url landing/authenticate,nameValuePairs);JSONObject jObject new JSONObject(content);JSONObject respObject jObject.getJSONObject(response);Boolean successrespObject.getBoolean(success);String messagerespObject.getString(message);Boolean logged_inrespObject.getBoolean(logged_in);if(logged_in){user_idrespObject.getInt(user_id);access_tokenrespObject.getString(access_token);usernamerespObject.getString(username);current_usernameusername;current_user_iduser_id;user_logged_intrue;//initFeeds(username);test(0);}else{createDialog(Error,message);}}catch(Exception e){}}解决方法:您可以使用应用共享偏好设置.可以使用为这些prefs设置的密钥随时访问prefsstatic final String KEY_USERNAME username;static final String KEY_PASSWORD password;if (rememberMe) { //save username and pw to prefsSharedPreferences prefs PreferenceManager.getDefaultSharedPreferences(this);Editor ed prefs.edit();ed.putString(KEY_USERNAME, theUsername);ed.putString(KEY_PASSWORD, thePW);ed.commit();}要访问信息,例如onCreate方法SharedPreferences prefs PreferenceManager.getDefaultSharedPreferences(this);String username prefs.getString(KEY_USERNAME, Default Value if not found);String password prefs.getString(KEY_PASSWORD, ); //return nothing if no pass saved来源https://www.icode9.com/content-1-401801.html