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

public class Main {
    private static final String LASTSYNC_PARAM = "lastSync";

    public static void updateLastSync(Context context) {
        long lastSync = getLastSync(context);
        long now = System.currentTimeMillis();
        if (lastSync < now) {
            SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
            SharedPreferences.Editor editor = prefs.edit();
            editor.putLong(LASTSYNC_PARAM, now);
            editor.commit();
        }
    }

    public static long getLastSync(Context context) {
        SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
        return prefs.getLong(LASTSYNC_PARAM, 0);
    }
}