save RSS Data to SharedPreferences - Android android.content

Android examples for android.content:SharedPreferences

Description

save RSS Data to SharedPreferences

Demo Code


//package com.java2s;
import android.app.Activity;
import android.content.Context;
import android.content.SharedPreferences;
import android.widget.Toast;
import java.util.Map;

public class Main {
    public static void saveRSSData(Activity activity, String name,
            String link) {/*w ww  .  ja v  a 2s.c o m*/
        SharedPreferences sp = activity
                .getPreferences(Context.MODE_PRIVATE);
        if (sp.contains(name)) {
            Toast.makeText(activity, "This NAME already exists.",
                    Toast.LENGTH_SHORT).show();
            return;
        }
        Map<String, String> map = (Map<String, String>) sp.getAll();
        for (Map.Entry<String, String> entry : map.entrySet()) {
            if (link.equals(entry.getValue())) {
                Toast.makeText(activity, "This LINK already exists.",
                        Toast.LENGTH_SHORT).show();
                return;
            }
        }

        sp.edit().putString(name, link).commit();
    }
}

Related Tutorials