https://github.com/blackbbc/luna
Android saved instance state helper
https://github.com/blackbbc/luna
Last synced: 9 months ago
JSON representation
Android saved instance state helper
- Host: GitHub
- URL: https://github.com/blackbbc/luna
- Owner: blackbbc
- Created: 2016-12-24T14:23:41.000Z (over 9 years ago)
- Default Branch: master
- Last Pushed: 2017-04-06T10:04:23.000Z (over 9 years ago)
- Last Synced: 2025-02-24T08:13:39.846Z (over 1 year ago)
- Language: Java
- Size: 108 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 1
-
Metadata Files:
- Readme: Readme.md
Awesome Lists containing this project
README
[](https://jitpack.io/#blackbbc/Luna)
[](https://travis-ci.org/blackbbc/Luna)
[](https://www.versioneye.com/user/projects/585ea6602e129e0047a7fc8e)
# Luna
Android instance state helper. It uses apt to generate codes.
## Download
Add in your root build.gradle:
```
allprojects {
repositories {
...
maven { url 'https://jitpack.io' }
}
}
```
Add in your app/build.gradle
```
dependencies {
annotationProcessor 'com.github.blackbbc.Luna:luna-processor:1.0.1'
compile 'com.github.blackbbc.Luna:luna-annotation:1.0.1'
}
```
## Usage
Use `@State` annotation to annotate variables that need to save.
``` Java
public class MainActivity extends AppCompatActivity {
@State int testInt;
@State Integer testInteger;
@State boolean testBoolean;
@State float testFloat;
@State String testString;
@State ArrayList integers;
@State List strings;
@State List products;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
@Override
protected void onSaveInstanceState(Bundle outState) {
super.onSaveInstanceState(outState);
}
}
```
Run "Build" to generate necessary helper codes. The helper codes is named by prefix `Luna` + `ClassName`. For example, the above `MainActivity` will generate `LunaMainActivity` class. Then add the following codes to use them!.
```Java
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
LunaMainActivity.onRestoreInstanceState(this, savedInstanceState);
}
@Override
protected void onSaveInstanceState(Bundle outState) {
super.onSaveInstanceState(outState);
LunaMainActivity.onSaveInstanceState(this, outState);
}
```
That's all!
## Support types:
1. Boxed and unboxed primitive type.
- `boolean`, `byte`, `short`, `int`, `long`, `char`, `float`, `double`
- `Boolean`, `Byte`, `Short`, `Int`, `Long`, `Char`, `Float`, `Double`
2. `String`
3. `Parcelable`
4. `List`, `List`, `List`