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.content.SharedPreferences.Editor;

public class Main {
    public static void writeSharedPreferences(Context context, String prefsName, String name, Object value) {
        if (name == null || value == null) {
            return;
        }
        SharedPreferences user = context.getSharedPreferences(prefsName, 0);
        Editor editor = user.edit();
        if (value instanceof Integer) {
            editor.putInt(name, Integer.parseInt(value.toString()));
        } else if (value instanceof Long) {
            editor.putLong(name, Long.parseLong(value.toString()));
        } else if (value instanceof Boolean) {
            editor.putBoolean(name, Boolean.parseBoolean(value.toString()));
        } else if (value instanceof String) {
            editor.putString(name, value.toString());
        } else if (value instanceof Float) {
            editor.putFloat(name, Float.parseFloat(value.toString()));
        }
        editor.commit();
    }
}