Php 如何将用户的用户ID从DB保存到my SharedReference?

Php 如何将用户的用户ID从DB保存到my SharedReference?,php,android,mysql,Php,Android,Mysql,我正在使用php和mysql进行登录,我还希望登录用户的用户ID将保存在SharedReference上。我不知道怎么做。 这是我的php登录 Login.php 这是数据库,我的数据库来自服务器 希望此代码对您有所帮助 希望此代码能帮助您以类似方式保存用户id String userId = "your user id string from server"; editor.putString("user id", userId); editor.apply(); 同样地保存用户id S

我正在使用php和mysql进行登录,我还希望登录用户的用户ID将保存在SharedReference上。我不知道怎么做。 这是我的php登录

Login.php 这是数据库,我的数据库来自服务器

希望此代码对您有所帮助


希望此代码能帮助您以类似方式保存用户id

String userId = "your user id string from server";

editor.putString("user id", userId);
editor.apply();

同样地保存用户id

String userId = "your user id string from server";

editor.putString("user id", userId);
editor.apply();

似乎您已经这样做了??只有用户名和密码保存到SharedReference中,先生@Jaspest将您的代码发布到获取用户的位置id@Jas-嗯,但是我没有,先生。发布的php代码是我获取用户名和密码的唯一方法…向我们展示登录成功时得到的响应似乎您已经这样做了??只有用户名和密码保存到SharedReference中,先生@Jaspest将您的代码发布到获取用户的位置id@Jas-嗯,但是我没有,先生。发布的php代码是我获取用户名和密码的唯一途径…向我们展示登录成功时得到的响应
Int
给了我一个错误,它说我应该按
String
操作。
Int
给了我一个错误,它说我应该按
String
操作。
public static final String pref_name = "your shared preference name";
    SharedPreferences settings = getSharedPreferences(pref_name, MODE_PRIVATE);
    SharedPreferences.Editor prefEditor = settings.edit();
    prefEditor.putString("userId", userId);
    prefEditor.commit();
String userId = "your user id string from server";

editor.putString("user id", userId);
editor.apply();