Skip to main content

Saved Perf in Android

Just add this class in your package 


package com.plzf1.rollearn;
import android.app.Application;import android.content.SharedPreferences;
public class MyApplication extends Application {


    public static final String MENULIST = "menulist";    public static final String VEGLIST="veglist";    public static final String CARTLIST="cartlist";    public static final String FRUITLIST ="fruitlist";    @Override    public void onCreate() {
        super.onCreate();    }

    public void saveIntoPrefs(String key, String value) {
        SharedPreferences prefs = getSharedPreferences(Fconstants.PREF_NAME,MODE_PRIVATE);        SharedPreferences.Editor edit = prefs.edit();        edit.putString(key, value);        edit.commit();
    }

    public void saveIntoPrefs(String key, int value) {
        SharedPreferences prefs = getSharedPreferences(Fconstants.PREF_NAME,MODE_PRIVATE);        SharedPreferences.Editor edit = prefs.edit();        edit.putInt(key, value);        edit.commit();
    }

    public void saveDoubleIntoPrefs(String key, double value) {
        SharedPreferences prefs = getSharedPreferences(Fconstants.PREF_NAME,MODE_PRIVATE);        SharedPreferences.Editor edit = prefs.edit();        edit.putLong(key, Double.doubleToRawLongBits(value));        edit.commit();
    }

    public String getFromPrefs(String key) {
        SharedPreferences prefs = getSharedPreferences(Fconstants.PREF_NAME,MODE_PRIVATE);        return prefs.getString(key, Fconstants.DEFAULT_VALUE);    }

    public double getDoubleFromPrefs(String key) {
        SharedPreferences prefs = getSharedPreferences(Fconstants.PREF_NAME,MODE_PRIVATE);        return Double.longBitsToDouble(prefs.getLong(key,                Double.doubleToLongBits(0)));    }

    public int getIntFromPrefs(String key) {
        SharedPreferences prefs = getSharedPreferences(Fconstants.PREF_NAME,MODE_PRIVATE);        return prefs.getInt(key, 0);    }

    public long getLongFromPrefs(String key) {
        SharedPreferences prefs = getSharedPreferences(Fconstants.PREF_NAME,MODE_PRIVATE);        return prefs.getLong(key, -1);    }

    public void clearPrefs() {
        SharedPreferences prefs = getSharedPreferences(Fconstants.PREF_NAME,MODE_PRIVATE);        prefs.edit().clear().commit();    }

//    public void storeMenuList(Context context, @SuppressWarnings("rawtypes") List favorites) {//        // used for store arrayList in json format//        SharedPreferences prefs = getSharedPreferences(Fconstants.PREF_NAME_A,MODE_PRIVATE);//        SharedPreferences.Editor editor;//        editor = prefs.edit();//        Gson gson = new Gson();//        String jsonFavorites = gson.toJson(favorites);//        editor.putString(MENULIST, jsonFavorites);//        editor.commit();//    }
//    public ArrayList<MenuListVO> getMenuList(Context context) {////        SharedPreferences prefs = getSharedPreferences(Fconstants.PREF_NAME_A,MODE_PRIVATE);//        List<MenuListVO> arrMenuList;//        if (prefs.contains(MENULIST)) {//            String jsonFavorites = prefs.getString(MENULIST, null);//            Gson gson = new Gson();//            MenuListVO[] favoriteItems = gson.fromJson(jsonFavorites,//                    MenuListVO[].class);////            arrMenuList = Arrays.asList(favoriteItems);//            arrMenuList = new ArrayList<MenuListVO>(arrMenuList);//        } else//            return null;////        return (ArrayList<MenuListVO>) arrMenuList;//    }////    public void storeVegitableList(Context context, @SuppressWarnings("rawtypes") List favorites) {//        // used for store arrayList in json format//        SharedPreferences prefs = getSharedPreferences(Fconstants.PREF_NAME_A,MODE_PRIVATE);//        SharedPreferences.Editor editor;//        editor = prefs.edit();//        Gson gson = new Gson();//        String jsonFavorites = gson.toJson(favorites);//        editor.putString(VEGLIST, jsonFavorites);//        editor.commit();//    }
//    public ArrayList<VegVo> getVegitableList(Context context) {////        SharedPreferences prefs = getSharedPreferences(Fconstants.PREF_NAME_A,MODE_PRIVATE);//        List<VegVo> arrveglist;//        if (prefs.contains(VEGLIST)) {//            String jsonFavorites = prefs.getString(VEGLIST, null);//            Gson gson = new Gson();//            VegVo[] favoriteItems = gson.fromJson(jsonFavorites,//                    VegVo[].class);////            arrveglist = Arrays.asList(favoriteItems);//            arrveglist = new ArrayList<VegVo>(arrveglist);//        } else//            return null;////        return (ArrayList<VegVo>) arrveglist;//    }
//    public void storeCartList(Context context, @SuppressWarnings("rawtypes") List cart) {//        // used for store arrayList in json format//        SharedPreferences prefs = getSharedPreferences(Fconstants.PREF_NAME_A,MODE_PRIVATE);//        SharedPreferences.Editor editor;//        editor = prefs.edit();//        Gson gson = new Gson();//        String jsonFavorites = gson.toJson(cart);//        editor.putString(CARTLIST, jsonFavorites);//        editor.commit();//    }

//    public ArrayList<cartVo> getcartList(Context context) {////        SharedPreferences prefs = getSharedPreferences(Fconstants.PREF_NAME_A,MODE_PRIVATE);//        List<cartVo> arrcartList;//        if (prefs.contains(CARTLIST)) {//            String jsonFavorites = prefs.getString(CARTLIST, null);//            Gson gson = new Gson();//            cartVo[] cartItems = gson.fromJson(jsonFavorites,//                    cartVo[].class);////            arrcartList = Arrays.asList(cartItems);//            arrcartList = new ArrayList<cartVo>(arrcartList);//        } else//            return null;////        return (ArrayList<cartVo>) arrcartList;//    }
//    public void storeFruitList(Context context, @SuppressWarnings("rawtypes") List cart) {//        // used for store arrayList in json format//        SharedPreferences prefs = getSharedPreferences(Fconstants.PREF_NAME_A,MODE_PRIVATE);//        SharedPreferences.Editor editor;//        editor = prefs.edit();//        Gson gson = new Gson();//        String jsonFavorites = gson.toJson(cart);//        editor.putString(FRUITLIST, jsonFavorites);//        editor.commit();//    }////    public ArrayList<FruitVo> getfruitList(Context context) {////        SharedPreferences prefs = getSharedPreferences(Fconstants.PREF_NAME_A,MODE_PRIVATE);//        List<FruitVo> arrfruitList;//        if (prefs.contains(FRUITLIST)) {//            String jsonFavorites = prefs.getString(FRUITLIST, null);//            Gson gson = new Gson();//            FruitVo[] cartItems = gson.fromJson(jsonFavorites,//                    FruitVo[].class);////            arrfruitList = Arrays.asList(cartItems);//            arrfruitList = new ArrayList<FruitVo>(arrfruitList);//        } else//            return null;////        return (ArrayList<FruitVo>) arrfruitList;//    }arrfruitList



}

Popular posts from this blog

How to create google map with drag marker to get user location with auto correct location edit text ...

For drag and drop with user location You have to create a google map fragment activity below are the xml code of google map xml <? xml version ="1.0" encoding ="utf-8" ?> < androidx.constraintlayout.widget.ConstraintLayout xmlns: android ="http://schemas.android.com/apk/res/android" xmlns: app ="http://schemas.android.com/apk/res-auto" xmlns: tools ="http://schemas.android.com/tools" android :layout_width ="match_parent" android :layout_height ="match_parent" tools :context =".GetUserLocationActivity" > < fragment android :id ="@+id/mapuserloc" android :name ="com.google.android.gms.maps.SupportMapFragment" android :layout_width ="match_parent" android :layout_height ="522dp" app :layout_constraintEnd_toEndOf ="parent" app :layout_constraintStart_toStartOf ="p...

create MVVM Architecture Pattern for my android app

Here is an example of how you could implement the MVVM (Model-View-ViewModel) architecture pattern in an Android app using Java: Create a View class, for example MainActivity that extends AppCompatActivity and is responsible for handling user interactions and displaying data to the user. public class MainActivity extends AppCompatActivity { private ActivityMainBinding binding; private MainViewModel viewModel; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); binding = DataBindingUtil.setContentView(this, R.layout.activity_main); viewModel = new ViewModelProvider(this).get(MainViewModel.class); binding.setViewModel(viewModel); binding.setLifecycleOwner(this); } } } } Create a ViewModel class, for example MainViewModel that extends AndroidViewModel and is responsible for holding and processing the data for the View , as well as handling any business logicy code public cla...

How to setup wifi ADB debugger for android studio

How to setup wifi ADB debugger for android studio  Firstly set your adb path Which you can find here Step 1:  Goto your  Android sdk folder -> platform tools  and copy the whole path For example:  C:\Program Files (x86)\Android\android-sdk\platform-tools Step 2:  Goto command prompt or Android studio terminal cd C:\Program Files (x86)\Android\android-sdk\platform-tools and presss enter Step 3:  Connect your device & system with same wifi. Step 4:  Type  adb tcpip 5555  and press  Enter . Step 5:  Type  adb connect x.x.x.x:5555 , replacing the  x.x.x.x  with your phone IP address. find out phone IP address Settings -> About phone -> Status  (some phones may be vary) Note: Incase if you connect more than one devices disconnect other phones except which one you need to connect