HawleyRetainer


Source link: https://github.com/jparkie/HawleyRetainer

HawleyRetainer

An Android annotation processing and code generation library to retain complex objects which cannot be parceled nor serialized into a Bundle across configuration changes.

It utilizes a retained fragment implementing the Map interface to provide identical operations to a Bundle.

It does not behave like a Singleton class as it observes the lifecycle of its bound Activity, thus, it destroys itself accordingly. This characteristic is useful to prevent fields being retained in memory beyond the user-initiated destruction of an Activity like a Singleton while still being retained during configuration changes.

Utilize this class as a means of simplifying the retention of certain expensive operations beyond configuration changes while obeying user-initiated lifecycle events such as concurrent, file input-output. or network operations.

Nonetheless, as the retained objects cannot be parceled nor serialized, they can still be claimed by the garbage collector resulting in the loss of data.

public class ExampleActivity extends Activity {

@HawleyRetain
Observable<Response> mNetworkResponse;

@Override
public void onCreate(Bundle savedInstanceState) {

  super.onCreate(savedInstanceState);

  HawleyRetainer.restoreRetainedObjectMap(this, this);

}

@Override
public void onSaveInstanceState(Bundle outState) {

  super.onSaveInstanceState(outState);

  HawleyRetainer.saveRetainedObjectMap(this, this);

}
 
}

Usage

@HawleyRetain // A single annotation used to annotate any number of fields which you want to retain.  public static <T> void saveRetainedObjectMap(T target, Activity activity);
  public static <T> void restoreRetainedObjectMap(T target, Activity activity);
  public static <T> Map retrieveRetainerFragmentMap(T target, Activity activity);

The methods can be called upon any target class as long as an Activity can be specified along with it. The retainer will recursively traverse the inheritance graph to inject all annotated fields. Please remember that the support library variants of Fragment and Activity extend from them. As a result, the methods do not have overloads.

Download

Preparing for Maven Central.

JitPack

Add the JitPack repository to your root build file:

repositories {

maven {

  url "https://jitpack.io"

}
 
}

Add the following Gradle plugin to your root build file to support annotation processing:

dependencies {

classpath 'com.neenbedankt.gradle.plugins:android-apt:1.4' 
}

In your project build file apply the plugin and include the library as a dependency:

apply plugin: 'com.neenbedankt.android-apt'  ...  dependencies {

apt 'com.github.jparkie:HawleyRetainer.compiler:1.0.1'
compile 'com.github.jparkie:HawleyRetainer.api:1.0.1' 
}

If you are using other annotation processing and code generation libraries like Dagger, do not state the dependency as provided. Instead state the dependency as apt such that the code generation will run over the classes: apt 'com.squareup.dagger:dagger-compiler:1.2.2'.

License

Copyright 2015 Jacob Park  Licensed under the Apache License, Version 2.0 (the "License");
 you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0  Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. 

Resources

SquareMenu is a custom Floating Action Button with a different shape from traditional FABs and with three sub menu buttons.

A simple helper library to request permissions in Android M and above.

This is a sample project which helps anybody who wish to work with GreenDAO library.

This application contains all the thing you need to start creating project using GreenDAO.

Easy way to put and get data and Object for the shared preferences in Android.

Make things easy when you need to write a sql statment for Android SQLite.

A library allowing you to manage Wi-Fi peer-to-peer connectivity in a reactive way. The library itself is a RxJava wrapper for Android's WifiP2pManager, used for discovering available peers, setup connection to peers and query for the list of peers.

When a p2p connection is formed over wifi, devices continue to maintain the uplink connection over mobile or any other available network for internet connectivity.

Topics


2D Engines   3D Engines   9-Patch   Action Bars   Activities   ADB   Advertisements   Analytics   Animations   ANR   AOP   API   APK   APT   Architecture   Audio   Autocomplete   Background Processing   Backward Compatibility   Badges   Bar Codes   Benchmarking   Bitmaps   Bluetooth   Blur Effects   Bread Crumbs   BRMS   Browser Extensions   Build Systems   Bundles   Buttons   Caching   Camera   Canvas   Cards   Carousels   Changelog   Checkboxes   Cloud Storages   Color Analysis   Color Pickers   Colors   Comet/Push   Compass Sensors   Conferences   Content Providers   Continuous Integration   Crash Reports   Credit Cards   Credits   CSV   Curl/Flip   Data Binding   Data Generators   Data Structures   Database   Database Browsers   Date &   Debugging   Decompilers   Deep Links   Dependency Injections   Design   Design Patterns   Dex   Dialogs   Distributed Computing   Distribution Platforms   Download Managers   Drawables   Emoji   Emulators   EPUB   Equalizers &   Event Buses   Exception Handling   Face Recognition   Feedback &   File System   File/Directory   Fingerprint   Floating Action   Fonts   Forms   Fragments   FRP   FSM   Functional Programming   Gamepads   Games   Geocaching   Gestures   GIF   Glow Pad   Gradle Plugins   Graphics   Grid Views   Highlighting   HTML   HTTP Mocking   Icons   IDE   IDE Plugins   Image Croppers   Image Loaders   Image Pickers   Image Processing   Image Views   Instrumentation   Intents   Job Schedulers   JSON   Keyboard   Kotlin   Layouts   Library Demos   List View   List Views   Localization   Location   Lock Patterns   Logcat   Logging   Mails   Maps   Markdown   Mathematics   Maven Plugins   MBaaS   Media   Menus   Messaging   MIME   Mobile Web   Native Image   Navigation   NDK   Networking   NFC   NoSQL   Number Pickers   OAuth   Object Mocking   OCR Engines   OpenGL   ORM   Other Pickers   Parallax List   Parcelables   Particle Systems   Password Inputs   PDF   Permissions   Physics Engines   Platforms   Plugin Frameworks   Preferences   Progress Indicators   ProGuard   Properties   Protocol Buffer   Pull To   Purchases   Push/Pull   QR Codes   Quick Return   Radio Buttons   Range Bars   Ratings   Recycler Views   Resources   REST   Ripple Effects   RSS   Screenshots   Scripting   Scroll Views   SDK   Search Inputs   Security   Sensors   Services   Showcase Views   Signatures   Sliding Panels   Snackbars   SOAP   Social Networks   Spannable   Spinners   Splash Screens   SSH   Static Analysis   Status Bars   Styling   SVG   System   Tags   Task Managers   TDD &   Template Engines   Testing   Testing Tools   Text Formatting   Text Views   Text Watchers   Text-to   Toasts   Toolkits For   Tools   Tooltips   Trainings   TV   Twitter   Updaters   USB   User Stories   Utils   Validation   Video   View Adapters   View Pagers   Views   Watch Face   Wearable Data   Wearables   Weather   Web Tools   Web Views   WebRTC   WebSockets   Wheel Widgets   Wi-Fi   Widgets   Windows   Wizards   XML   XMPP   YAML   ZIP Codes