Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;
/*
 * Hewlett-Packard Company
 * All rights reserved.
 *
 * This file, its contents, concepts, methods, behavior, and operation
 * (collectively the "Software") are protected by trade secret, patent,
 * and copyright laws. The use of the Software is governed by a license
 * agreement. Disclosure of the Software to third parties, in any form,
 * in whole or in part, is expressly prohibited except as authorized by
 * the license agreement.
 */

import android.app.Activity;

import android.content.SharedPreferences;

import android.preference.PreferenceManager;

public class Main {
    public static int getNextEventCounter(Activity hostActivity, String key) {
        SharedPreferences preferences = PreferenceManager
                .getDefaultSharedPreferences(hostActivity.getApplicationContext());

        int id = preferences.getInt(key, 0);
        id += 1;

        SharedPreferences.Editor editor = preferences.edit();
        editor.putInt(key, id).commit();

        return id;
    }
}