Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;
import android.content.Context;
import android.content.SharedPreferences;
import android.preference.PreferenceManager;
import java.util.HashSet;
import java.util.Set;

public class Main {
    public static final String PREF_FAVORED_MOVIES = "pref_favored_movies";

    public static void removeFromFavorites(final Context context, long movieId) {
        SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(context);
        Set<String> set = sp.getStringSet(PREF_FAVORED_MOVIES, null);
        if (set == null)
            set = new HashSet<>();
        set.remove(String.valueOf(movieId));
        sp.edit().putStringSet(PREF_FAVORED_MOVIES, set).apply();
    }
}