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 long getLongPreferences(Context context, String name) {
        try {
            return context.getSharedPreferences(SHARED_PREFERENCE_NAME, Context.MODE_PRIVATE).getLong(name, 0);
        } catch (Exception e) {
            Log.e("datautils", e.getMessage());
            remove(context, name);
        }
        return 0;
    }

    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() + "");
        }
    }
}