Q:

can't get data from SharedPreferences

First of all I call getFriends. Using Request I get data. It work correctly and gives not null
getFriends(getActivity());

 private void getFriends(final Context context){
    VKRequest request = VKApi.friends().get(VKParameters.from(VKApiConst.FIELDS,
            "id,first_name,last_name,photo_100,"));
    request.executeWithListener(new VKRequest.VKRequestListener() {
        @Override
        public void onComplete(VKResponse response) {
            super.onComplete(response);
            VKList<VKApiUser> Friends= (VKList<VKApiUser>)response.parsedModel;

            SharedPreferences prefs  = PreferenceManager.getDefaultSharedPreferences(context);
            SharedPreferences.Editor editor = prefs.edit();

            Toast.makeText(context,Friends.get(0).last_name,Toast.LENGTH_LONG).show();//NOT NULL

            for(int i = 0; i< Friends.size();++i) {
                editor.putString("FriendFirstName" + String.valueOf(i), "asdsaddsa");
                editor.putString("FriendLastName"+ String.valueOf(i), Friends.get(i).last_name);
                editor.putString("FriendPhoto"+ String.valueOf(i), Friends.get(i).photo_100);
            }
        }
    });
}

Then I call LoadData and try to get data from it 
LoadFriends(getActivity());

 public void LoadFriends(Context context){
        SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
        for(int i=0;i< 7; i++) {
            if (prefs != null) {
                Names.add(prefs.getString("FriendFirstName" + String.valueOf(i), null)
                        + " " + prefs.getString("FriendLastName" + String.valueOf(i), null));
            }
        }
}

And it puts me data that was previoud time, I mean it doesn't give me corrent data;
What am I doing wrong?

A:

You need to call commit() or apply() on your SharedPreferences.Editor so that the changes are persisted.

