Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;

import android.app.Activity;
import android.content.Context;
import android.content.SharedPreferences;

import android.util.Log;

public class Main {
    private static final String TAG = "CommonUtils";

    public static String getString(Context context, String category, String key) {
        String defaultValue = "";
        try {
            SharedPreferences setMyPref = context.getSharedPreferences(category, Activity.MODE_WORLD_READABLE);
            return setMyPref.getString(key, defaultValue);
        } catch (Exception e) {
            Log.e(TAG, "Error when getString, return defaultValue " + defaultValue, e);
            return defaultValue;
        }
    }
}