shrikanthkr/saveinstance-api


An annotation processor which helps to save and restore instance.

Download


Step 1. Add the JitPack repository to your build file

Add it in your root settings.gradle at the end of repositories:

	dependencyResolutionManagement {
		repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)
		repositories {
			mavenCentral()
			maven { url 'https://jitpack.io' }
		}
	}

Add it in your settings.gradle.kts at the end of repositories:

	dependencyResolutionManagement {
		repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)
		repositories {
			mavenCentral()
			maven { url = uri("https://jitpack.io") }
		}
	}

Add to pom.xml

	<repositories>
		<repository>
		    <id>jitpack.io</id>
		    <url>https://jitpack.io</url>
		</repository>
	</repositories>

Add it in your build.sbt at the end of resolvers:

 
    resolvers += "jitpack" at "https://jitpack.io"
        
    

Add it in your project.clj at the end of repositories:

 
    :repositories [["jitpack" "https://jitpack.io"]]
        
    

Step 2. Add the dependency

	dependencies {
		implementation 'com.github.shrikanthkr:saveinstance-api:'
	}
	dependencies {
		implementation("com.github.shrikanthkr:saveinstance-api:")
	}
	<dependency>
	    <groupId>com.github.shrikanthkr</groupId>
	    <artifactId>saveinstance-api</artifactId>
	    <version></version>
	</dependency>

                            
    libraryDependencies += "com.github.shrikanthkr" % "saveinstance-api" % ""
        
        

                            
    :dependencies [[com.github.shrikanthkr/saveinstance-api ""]]
        
        

Readme


This is still in progress, it can break at anytime.

Currently supports String, Boolean, boolean, int, Integer.

Usage:

Step 1

<pre><code> android{...} repositories { maven { url "https://jitpack.io" } }</code></pre>

Step 2

<pre><code> android{...} buildscript { repositories { mavenCentral() } dependencies { classpath 'com.neenbedankt.gradle.plugins:android-apt:1.8' } } apply plugin: 'com.neenbedankt.android-apt'</code></pre>

Step 3

<pre><code> android{...} dependencies { apt 'com.github.shrikanthkr:saveinstance-processor:v0.0.3' compile 'com.github.shrikanthkr:saveinstance-api:-SNAPSHOT' }</code></pre>

Sample

  • In your activity code
<pre><code> @SaveInstance String hello; </code></pre>
  • <b>OnCreate Method</b>
<pre><code> @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); if(savedInstanceState != null) { Retainer.load(this, savedInstanceState); } } </code></pre>
  • <b>OnSaveInstanceState Method</b>
<pre><code> @Override protected void onSaveInstanceState(Bundle outState) { super.onSaveInstanceState(outState); Retainer.save(this, outState); } </code></pre>