Visit GitHub RepoActivities

Prevailer - Orientation Support Android

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

Integrating the project is simple a refined all you need to do is follow the below steps

  • Add the JitPack repository to your build file. Add it in your root build.gradle at the end of repositories:
allprojects {
  repositories {
    maven { url "" }
  • Add the dependency
dependencies {
        compile 'com.github.mukeshsolanki:Prevailer-orientation-support-library-for-Android:1.0.2'
  • In your Activity / Fragment onCreate call
		this, // activity instance
		23, // unique id of loader used
		new PrevailerFactory<ObjectToBePreserved>() { // factory for the instance that should be preserved
		    public ObjectToBePreserved create() {
		        return new MyTypeToBePreserved();
		new Prevailer.OnInstanceReloadedAction<ObjectToBePreserved>() {
		    public void performAction(MyTypeToBePreserved instance) {
          // do what needs to be done when reloaded
		new Prevailer.OnInstanceDestroyedAction() {
		    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.

Become a better Android Developer
Millions of developers are learning at MindOrks

Online Training Program

Featured Blogs

Our Team

MindOrks is Certainly one of the best online blog to stay on top of all the Android development news, coding and design patterns. Finally a blog I can count on to keep myself updated with latest and greatest things happening in Android world.

Vipul Shah
Android Developer

Become Pro in Android by watching videos