티스토리 뷰

simple-shared-preferences

simple uses shared-preferences support generic and rxjava for andoird

Initialize

public class DemoApplication extends Application {

    @Override
    protected void onCreate() {
        super.onCreate(savedInstanceState);
        // apply default shared preferences file name.
        SimpleSharedPreferences.initialize(this);
        // apply custom shared preferences file name.
        SimpleSharedPreferences.initialize(this, "custom file name");
    }
}

Example

public class DemoActivity extends Activity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); // put value // supported value type : String, Set<String>, long, int, float, boolean, T SimpleSharedPreferences.put(key, value); // get value SimpleSharedPreferences.getValue(key, defaultValue); // get T SimpleSharedPreferences.getValue(key, class); // Rx SimpleSharedPreferences.Rx.put("demo","demo value").subscribe(value -> Log.d("demo",value)); SimpleSharedPreferences.Rx.getValue("demo","demo value").subscribe(value -> Log.d("demo",value)); } }

Download

Maven:

<dependency> <groupId>com.parkwoocheol</groupId> <artifactId>simple-shared-preferences</artifactId> <version>1.0.2</version> <type>pom</type> </dependency>

Gradle:

implementation 'com.parkwoocheol:simple-shared-preferences:1.0.2'

RxJava might not be available to the class loader. This can result in an exception that looks like this

Error:(20, 35) error: cannot access Observable
class file for io.reactivex.Observable not found

This can be fixed by either adding RxJava to your project Gradle:

// see https://github.com/ReactiveX/RxJava/releases for latest 2.x.x version implementation 'io.reactivex.rxjava2:rxjava:2.x.x' implementation 'com.parkwoocheol:simple-shared-preferences:1.0.2'

Developed By

License

Copyright (C) 2018 Park, Woocheol

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

   http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.


'Programming Story > Android' 카테고리의 다른 글

유용한 안드로이드 라이브러리 SimpleLog  (1) 2018.04.14