Skip to content
/ Stash Public
forked from akshay2211/Stash

This Library allows you to store custom objects and arrrayLists in SharedPreference just like you store string and int.

License

Notifications You must be signed in to change notification settings

konamgil/Stash

 
 

Repository files navigation

Stash

This Library allows you to store custom objects and arrrayLists in SharedPreference just like you store string and int.

Android Arsenal Download API

Usage

Stash needs to be initialized. You should only do this 1 time, so placing the initialization in your Application is a good idea. An example for this would be:

       [MyApplication.java]
       public class MyApplication extends Application {
           @Override
           public void onCreate() {
               super.onCreate();
               Stash.init(this);
           }
       }

Remember to also declare you Application class in the AndroidManifest.xml

         <manifest
             ...
             >
            <application
               ...
               android:label="@string/app_name"
               android:name=".MyApplication"
               >
               ...
             </application>
             ...
           </manifest>

for custom object

       class User{
              public Name;
              public Age;
              }
              
       User user = new User();
       
       Stash.put("TAG_DATA_OBJECT",user)
       User userNew = Stash.getObject("TAG_DATA_OBJECT", User.class);

for custom arraylist

     
       ArrayList<User> userArrayList = new ArrayList<>();
       userArrayList.add(new User("Akshay",12));
       userArrayList.add(new User("Aman",11));
       
       Stash.put("TAG_DATA_ARRAYLIST",userArrayList);
       ArrayList<User> userArrayListNew = Stash.getArrayList("TAG_DATA_ARRAYLIST", User.class);

for String

       Stash.put("TAG_DATA_STRING","Hello World");
       String Hi = Stash.getString("TAG_DATA_STRING"); //Hi = "Hello World"

for StringSet

       Set<String> strings = new HashSet<>();
       strings.add("one");
       strings.add("two");
       strings.add("three");
       Stash.put("TAG_DATA_STRING_SET",strings);
       Set<String> stringsNew = Stash.getStringSet("TAG_DATA_STRING_SET"); 

for int

       Stash.put(5,"TAG_DATA_INT");
       int i = Stash.getInt("TAG_DATA_INT"); //i = 5

for long

       Stash.put("TAG_DATA_LONG",987654321);
       long i = Stash.getLong("TAG_DATA_LONG"); //i = 987654321

for float

       Stash.put("TAG_DATA_INT",5.0f);
       int i = Stash.getInt("TAG_DATA_FLOAT"); //i = 5.0f

for boolean

       Stash.put("TAG_DATA_BOOLEAN",true);
       boolean val = Stash.getBoolean("TAG_DATA_BOOLEAN"); //val = true;

Download

Download or grab via Gradle:

        compile 'com.fxn769:stash:1.2'

or Maven:

        <dependency>
          <groupId>com.fxn769</groupId>
          <artifactId>stash</artifactId>
          <version>1.2</version>
          <type>pom</type>
        </dependency>

or ivy:

        <dependency org='com.fxn769' name='stash' rev='1.2'>
          <artifact name='stash' ext='pom' ></artifact>
        </dependency>

Snapshots of the development version are available in Sonatype's snapshots repository.

License

Licensed under the Apache License, Version 2.0, click here for the full license.

Author & support

This project was created by Akshay Sharma.

If you appreciate my work, consider buying me a cup of ☕ to keep me recharged 🤘 by PayPal

I love using my work and I'm available for contract work. Freelancing helps to maintain and keep my open source projects up to date!

forthebadge

About

This Library allows you to store custom objects and arrrayLists in SharedPreference just like you store string and int.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Java 100.0%