Jennifer
Jennifer

Reputation: 1852

Saving String data to SharedPreference then append to Uri

I want to make a Uri String like "http://almond.com/iOS/html/best.php?best_id=30241,15890"

The parameters of best_id (30241 and 15890) is retrieved like this from a custom url

       String[] path = uri.getPath().split("/");
        String sid = path[path.length - 1];

The problem is I want to keep appending a parameter with a comma after a click. But I'm not sure how I can append a parameter to a url string and save it to the same sharedPreference.

sample

pref = getSharedPreferences("pref", MODE_APPEND);
        SharedPreferences.Editor savestamp = pref.edit();


        StringBuilder sb = new StringBuilder();
        for (int i = 0; i < sid.length; i++) {
            sb.append(sid[i]).append(",");
        }
        savestamp.putString("params2", sb.toString());

I'm trying to do it but since I'm a total noob,just googling wont help. I would be grateful if the pros here can help me out.

Upvotes: 0

Views: 68

Answers (2)

J.K
J.K

Reputation: 2393

please add savestamp.commit(); after savestamp.putString method then only it saved to SharedPreference

Upvotes: 1

Rathan Kumar
Rathan Kumar

Reputation: 2577

Commit after putting the values.

pref = getSharedPreferences("pref", MODE_APPEND);
        SharedPreferences.Editor savestamp = pref.edit();


        StringBuilder sb = new StringBuilder();
        for (int i = 0; i < sid.length; i++) {
            sb.append(sid[i]).append(",");
        }
        savestamp.putString("params2", sb.toString());

savestamp.commit();

Upvotes: 1

Related Questions