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;

public class Main {
    private final static String PREF_NAME = "search_history";
    private final static String KEY_SEARCH_HISTORY = "history_record";

    public static void setCache(String value, Context ctx) {
        setString(ctx, KEY_SEARCH_HISTORY, value);
    }

    public static void setString(Context ctx, String key, String value) {
        SharedPreferences sp = ctx.getSharedPreferences(PREF_NAME, Context.MODE_PRIVATE);
        sp.edit().putString(key, value).apply();
    }
}