Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/evant/typedbundle
Typesafe key-value parinings for Android Bundles.
https://github.com/evant/typedbundle
Last synced: about 1 month ago
JSON representation
Typesafe key-value parinings for Android Bundles.
- Host: GitHub
- URL: https://github.com/evant/typedbundle
- Owner: evant
- License: apache-2.0
- Created: 2015-01-02T02:44:04.000Z (almost 10 years ago)
- Default Branch: main
- Last Pushed: 2020-06-14T22:52:30.000Z (over 4 years ago)
- Last Synced: 2023-03-22T12:35:41.419Z (almost 2 years ago)
- Language: Java
- Size: 71.3 KB
- Stars: 4
- Watchers: 2
- Forks: 0
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
TypedBundle
===========Typesafe key-value pairings for Android Bundles.
## Usage
The idea here is extreamly simple. Instead of using string contants for you bundle's keys, you just use intances of `Key` instead. This way the type of the value can be enforced at compile time.
```java
import me.tatarka.typedbundle.Key;public static final Key EXTRA_NAME = new Key<>("name");
public static final Key EXTRA_AGE = new Key<>("age");
```You can then use the `TypedBundle` wrapper class to put and get values from your Bundle.
```java
import me.tatarka.typedbundle.TypedBundle;TypedBundle typedBundle = new TypedBundle()
.put(EXTRA_NAME, "Bob")
.put(EXTRA_AGE, 42);
startActivity(new Intent().putExtras(typedBundle.getBundle()));
...
TypedBundle typedBundle = new TypedBundle(getIntent().getExtras());
String name = typedBundle.get(EXTRA_NAME);
int age = typedBundle.get(EXTRA_AGE, 0); // defaults supported for any value.
```That's it! The values are stored in the bundle exactly how you'd expect so you can use this to interface with existing code no problem.