{"id":15040795,"url":"https://github.com/evernote/android-state","last_synced_at":"2025-05-16T14:04:51.285Z","repository":{"id":57719164,"uuid":"79270127","full_name":"Evernote/android-state","owner":"Evernote","description":"A utility library for Android to save objects in a Bundle without any boilerplate.","archived":false,"fork":false,"pushed_at":"2019-09-29T22:09:34.000Z","size":551,"stargazers_count":858,"open_issues_count":1,"forks_count":49,"subscribers_count":32,"default_branch":"master","last_synced_at":"2025-05-16T14:04:49.742Z","etag":null,"topics":["android","android-application","annotation-processor","boilerplate","icepick","kotlin","kotlin-android"],"latest_commit_sha":null,"homepage":"","language":"Java","has_issues":false,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"epl-1.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/Evernote.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2017-01-17T20:45:28.000Z","updated_at":"2025-03-03T11:05:48.000Z","dependencies_parsed_at":"2022-08-26T09:41:26.576Z","dependency_job_id":null,"html_url":"https://github.com/Evernote/android-state","commit_stats":null,"previous_names":[],"tags_count":20,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Evernote%2Fandroid-state","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Evernote%2Fandroid-state/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Evernote%2Fandroid-state/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Evernote%2Fandroid-state/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Evernote","download_url":"https://codeload.github.com/Evernote/android-state/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":254544146,"owners_count":22088807,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["android","android-application","annotation-processor","boilerplate","icepick","kotlin","kotlin-android"],"created_at":"2024-09-24T20:45:05.100Z","updated_at":"2025-05-16T14:04:51.266Z","avatar_url":"https://github.com/Evernote.png","language":"Java","funding_links":[],"categories":[],"sub_categories":[],"readme":"# DEPRECATED\n\nThis library is not maintained anymore.\n\n# ~~Android-State~~\n\nA utility library for Android to save objects in a `Bundle` without any boilerplate. It uses an annotation processor to wire up all dependencies.\n\n## Download\n\nDownload the latest [library](https://search.maven.org/#search%7Cga%7C1%7Ca%3A%22android-state%22) and [processor](https://search.maven.org/#search%7Cga%7C1%7Ca%3A%22android-state-processor%22) or grab via Gradle:\n\n```groovy\ndependencies {\n    implementation 'com.evernote:android-state:1.4.1'\n    // Java only project\n    annotationProcessor 'com.evernote:android-state-processor:1.4.1'\n\n    // Kotlin with or without Java\n    kapt 'com.evernote:android-state-processor:1.4.1'\n}\n```\n\nYou can read the [JavaDoc here](https://evernote.github.io/android-state/javadoc/).\n\n## Usage\n\nIt's recommended to turn on a global setting in your `Application` class to save and restore the instance state of all activities and fragments from the support library. After that you only need to annotate your fields with `@State` inside of your fragments and activities. You can save any type which can be saved in a `Bundle` like the `String`, `Serializable`, and `Parcelable` data structures.\n\n```java\npublic class App extends Application {\n    @Override\n    public void onCreate() {\n        super.onCreate();\n        StateSaver.setEnabledForAllActivitiesAndSupportFragments(this, true);\n    }\n}\n\npublic class MainActivity extends Activity {\n\n    @State\n    public int mValue;\n\n    // ...\n}\n\nclass MainFragment : Fragment() {\n\n    @State\n    var title = \"My fragment\"\n}\n```\n\nIf you want to save the state of any other object or didn't turn on the global setting, then you need to use the `StateSaver` class for manually saving and restoring the instance state.\n\n```java\npublic class MainActivity extends Activity {\n\n    @State\n    public int mValue;\n\n    @Override\n    protected void onCreate(Bundle savedInstanceState) {\n        super.onCreate(savedInstanceState);\n        StateSaver.restoreInstanceState(this, savedInstanceState);\n    }\n\n    @Override\n    protected void onSaveInstanceState(Bundle outState) {\n        super.onSaveInstanceState(outState);\n        StateSaver.saveInstanceState(this, outState);\n    }\n}\n```\n\n## Advanced\n\nYou can also save state in a `View` class.\n\n```java\npublic class TestView extends View {\n\n    @State\n    public int mState;\n\n    public TestView(Context context) {\n        super(context);\n    }\n\n    @Override\n    protected Parcelable onSaveInstanceState() {\n        return StateSaver.saveInstanceState(this, super.onSaveInstanceState());\n    }\n\n    @Override\n    protected void onRestoreInstanceState(Parcelable state) {\n        super.onRestoreInstanceState(StateSaver.restoreInstanceState(this, state));\n    }\n}\n```\n\nIt is recommended that saved properties not be `private`. If a property is `private`, then a non-private getter and setter method are required. This is especially useful for Kotlin, because properties are `private` by default and the aforementioned methods are generated by the compiler.\n\nIf you **want** your getter and setter to be used rather than the field value being used directly, the field **must** be private.\n\n```kotlin\nclass DemoPresenter : Presenter\u003cDemoView\u003e() {\n\n    @State\n    var counter = 0\n\n    // ...\n}\n\n```\n\nOf course, this also works in Java.\n\n```java\npublic class TitleUpdater {\n\n    @State\n    private String mTitle;\n\n    public String getTitle() {\n        return mTitle;\n    }\n\n    public void setTitle(String title) {\n        mTitle = title;\n    }\n}\n```\n\nIf you have a private field and don't want to provide a getter or setter method, then you can fallback to reflection. However, this method is not recommended.\n\n```java\npublic class ImageProcessor {\n\n    @StateReflection\n    private byte[] mImageData;\n\n    // ...\n}\n```\n\nA custom bundler can be useful, if a class doesn't implement the `Parcelable` or `Serializable` interface, which oftentimes happens with third party dependencies.\n\n```java\npublic class MappingProvider {\n\n    @State(PairBundler.class)\n    public Pair\u003cString, Integer\u003e mMapping;\n\n    public static final class PairBundler implements Bundler\u003cPair\u003cString, Integer\u003e\u003e {\n        @Override\n        public void put(@NonNull String key, @NonNull Pair\u003cString, Integer\u003e value, @NonNull Bundle bundle) {\n            bundle.putString(key + \"first\", value.first);\n            bundle.putInt(key + \"second\", value.second);\n        }\n\n        @Nullable\n        @Override\n        public Pair\u003cString, Integer\u003e get(@NonNull String key, @NonNull Bundle bundle) {\n            if (bundle.containsKey(key + \"first\")) {\n                return new Pair\u003c\u003e(bundle.getString(key + \"first\"), bundle.getInt(key + \"second\"));\n            } else {\n                return null;\n            }\n        }\n    }\n}\n```\n\n### Lint\n\nThe library comes with Lint rules to verify a correct usage of the library. The lint checks work in Java and Kotlin files.\n\n### ProGuard\n\nThis library comes with a ProGuard config. No further steps are required, but all necessary rules can be found [here](library/proguard.cfg).\n\n## [Icepick](https://github.com/frankiesardo/icepick)\n\nThis library is based on [Icepick](https://github.com/frankiesardo/icepick), a great library from Frankie Sardo. However, Icepick is missing some features important to us: it [doesn't support properties](https://github.com/frankiesardo/icepick/issues/81) which is a [bummer for Kotlin](https://github.com/frankiesardo/icepick/issues/47). Also, Icepick does not support private fields which may break encapsulation. A tool shouldn't force you into this direction.\n\nSince Icepick is implemented in Clojure, we decided that it's better for us to rewrite the annotation processor in Java. Unfortunately, that makes it hard to push our features into Icepick itself. That's why we decided to fork the project.\n\nThere are also alternatives for Kotlin like [IceKick](https://github.com/tinsukE/icekick). We did not want to use two libraries to solve the same problem for two different languages; we wanted to have one solution for all scenarios.\n\nUpgrading to this library from Icepick is easy. The API is the same; only the packages and the class name (i.e. from `Icepick` to `StateSaver`) have changed. If Icepick works well for you, then there's no need to upgrade.\n\n## License\n\n```\nCopyright (c) 2017 Evernote Corporation.\nAll rights reserved. This program and the accompanying materials\nare made available under the terms of the Eclipse Public License v1.0\nwhich accompanies this distribution, and is available at\n\nhttp://www.eclipse.org/legal/epl-v10.html\n\nFiles produced by Android-State code generator are not subject to terms\nof the Eclipse Public License 1.0 and can be used as set out in the\ncopyright notice included in the generated files.\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fevernote%2Fandroid-state","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fevernote%2Fandroid-state","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fevernote%2Fandroid-state/lists"}