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.util.Log;

public class Main {
    private final static String SHARED_PREFERENCE_NAME = "SC_SHARED_PREFERENCE";

    public static void setLongPreferences(Context context, String name, long value) {
        try {
            SharedPreferences.Editor editor = context
                    .getSharedPreferences(SHARED_PREFERENCE_NAME, Context.MODE_PRIVATE).edit();
            editor.putLong(name, value);
            editor.commit();
        } catch (Exception e) {
            Log.e("datautils", e.getMessage());
            remove(context, name);
        }
    }

    public static void remove(Context context, String name) {
        try {
            SharedPreferences.Editor editor = context
                    .getSharedPreferences(SHARED_PREFERENCE_NAME, Context.MODE_PRIVATE).edit();
            editor.remove(name);
            editor.commit();
        } catch (Exception e) {
            Log.e("datautils", e.getMessage() + "");
        }
    }
}