Stash

Additional

Language
Java
Version
N/A
Created
Mar 3, 2018
Updated
Mar 6, 2022 (Retired)
Owner
Akshay Sharma (akshay2211)
Contributors
Codacy Badger (codacy-badger)
Akshay Sharma (akshay2211)
thrashedbrain
3
Activity
Badge
Generate
Download
Source code

Advertisement

Stash

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

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

or grab via Gradle:

        implementation 'com.fxn769:stash:1.3.2'

or Maven:

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

or ivy:

        <dependency org='com.fxn769' name='stash' rev='1.3.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