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;

import java.util.ArrayList;
import java.util.List;

public class Main {
    public static List<String> mDishLikeList = new ArrayList<>();

    public static boolean saveArray(Context mContext) {
        SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(mContext);
        SharedPreferences.Editor mEdit1 = sp.edit();
        mEdit1.putInt("Like_size", mDishLikeList.size());

        for (int i = 0; i < mDishLikeList.size(); i++) {
            mEdit1.remove("Like_" + i);
            mEdit1.putString("Like_" + i, mDishLikeList.get(i));
        }

        return mEdit1.commit();
    }
}