This Library allows you to store custom objects and arrrayLists in SharedPreference just like you store string and int.
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>
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);
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);
Stash.put("TAG_DATA_STRING","Hello World");
String Hi = Stash.getString("TAG_DATA_STRING"); //Hi = "Hello World"
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");
Stash.put(5,"TAG_DATA_INT");
int i = Stash.getInt("TAG_DATA_INT"); //i = 5
Stash.put("TAG_DATA_LONG",987654321);
long i = Stash.getLong("TAG_DATA_LONG"); //i = 987654321
Stash.put("TAG_DATA_INT",5.0f);
int i = Stash.getInt("TAG_DATA_FLOAT"); //i = 5.0f
Stash.put("TAG_DATA_BOOLEAN",true);
boolean val = Stash.getBoolean("TAG_DATA_BOOLEAN"); //val = true;
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.
Licensed under the Apache License, Version 2.0, click here for the full license.