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.preference.PreferenceManager;

public class Main {
    /**
     * Get the shared preference about knn from localization method.
     *
     * @param context The calling context.
     * @return Integer from preferences. If not a number, return value will be 3.
     */
    public static int getPrefKnn(Context context) {
        SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(context);
        int value = 3;

        try {
            value = Integer.valueOf(sharedPreferences.getString("localization_knn", "3"));
        } catch (NumberFormatException e) {
            e.printStackTrace();
        }

        return value;
    }
}