Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;
//License from project: Apache License 

import android.content.Context;
import android.content.SharedPreferences;

public class Main {
    public static final String DEFAULT_FILE_NAME = "playTogetherAttr";

    public static void increment(Context context, String key, int amount) {
        SharedPreferences sp = context.getSharedPreferences(DEFAULT_FILE_NAME, Context.MODE_PRIVATE);
        int count = sp.getInt(key, -1);
        if (count == -1)
            count = 0;
        count++;
        SharedPreferences.Editor editor = context.getSharedPreferences(DEFAULT_FILE_NAME, Context.MODE_PRIVATE)
                .edit();
        editor.putInt(key, count);
        editor.commit();
    }
}