Giter Club home page Giter Club logo

prevailer-orientation-support-library-for-android's Introduction

Prevailer

PayPal

Prevailer is a simple android library that helps in preserving object instances across orientation change in android and is JAVA 8 and MVP ready.

How to use

  • Add the dependency
	dependencies {
	  compile 'com.mukesh:prevailer:1.0.0'
	}
  • In your Activity / Fragment onCreate call
Prevailer.init(
		this, // activity instance
		23, // unique id of loader used
		new PrevailerFactory<ObjectToBePreserved>() { // factory for the instance that should be preserved
		    @Override
		    public ObjectToBePreserved create() {
		        return new MyTypeToBePreserved();
		    }
		},
		new Prevailer.OnInstanceReloadedAction<ObjectToBePreserved>() {
		    @Override
		    public void performAction(MyTypeToBePreserved instance) {
          // do what needs to be done when reloaded
		    }
		},
		new Prevailer.OnInstanceDestroyedAction() {
		    @Override
		    public void performAction() {
          // do what needs to be done when destroyed
		    }
		}
);
  • Use with JAVA 8
Prevailer.init(this, 23,
                (PrevailerFactory<MyTypeToBePreserved>) () -> new ObjectToBePreserved(),
                (Prevailer.OnInstanceReloadedAction<ObjectToBePreserved>) instance -> {
                    // do what needs to be done when reloaded
                },
                (Prevailer.OnInstanceDestroyedAction) () -> {
                    // do what needs to be done when destroyed
                }
);

Why do we need Prevailer

The need for prevailer has been around from a very long time the developers in the android community have been fighting this issue from a really long time. Prevailer works with MVP approach making development easy in case where the presenters had to be maintained or kept alive when the orientation changed.

How does it work

Prevailer uses Android Loader API under the hood. On Android platform, Loaders framework provides API for asynchronous data loading in Activity or Fragment. However, Loaders has special property of preserving instance of the handled object when it's reloaded. Prevailer benefits from that to provide simple way of caching (preserving) instances of objects that mustn't be destroyed during orientation changes. Preserved instances are destroyed when the activity holding them is abandoned and no longer used.

prevailer-orientation-support-library-for-android's People

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.