Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;
/*******************************************************************************
 * Copyright (c) 2013 Ulrik Andersson.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the GNU Public License v3.0
 * which accompanies this distribution, and is available at
 * http://www.gnu.org/licenses/gpl.html
 * 
 * Contributors:
 *     Ulrik Andersson - initial API and implementation
 ******************************************************************************/

import java.io.IOException;
import java.io.ObjectInputStream;

import android.content.SharedPreferences.Editor;

public class Main {
    public static void RestoreSharedPrefencesFromStream(ObjectInputStream input, Editor editor)
            throws IOException, ClassNotFoundException {
        int size = input.readInt();
        for (int i = 0; i < size; i++) {
            String key = input.readUTF();
            Object val = input.readObject();
            if (val instanceof Boolean)
                editor.putBoolean(key, ((Boolean) val).booleanValue());
            else if (val instanceof Float)
                editor.putFloat(key, ((Float) val).floatValue());
            else if (val instanceof Integer)
                editor.putInt(key, ((Integer) val).intValue());
            else if (val instanceof Long)
                editor.putLong(key, ((Long) val).longValue());
            else if (val instanceof String)
                editor.putString(key, ((String) val));
        }
        editor.commit();
    }
}