SafelyAndroid


Source link: https://github.com/Piasy/SafelyAndroid

SafelyAndroid

Build safely Android app, no more Activity not found, Activity state loss and NPE during fragment transaction!

Pause-safe fragment transaction

Dependency

Add to gradle dependency of your module build.gradle:

repositories {

  jcenter() 
}
  dependencies {

  compile 'com.github.piasy:safelyandroid:1.2.0' 
}

Usage

Start activity safely

Start activity from context, fragment and support v4 fragment, and start activity for result from activity, fragment and support v4 fragment, with or without the optional bundle options. StartActivityDelegate will launch the intent only when its component exist, otherwise, it will return false. Never get activity not found error again!

StartActivityDelegate.startActivitySafely(fragment, intent)  StartActivityDelegate.startActivitySafely(fragment, intent, options)  StartActivityDelegate.startActivityForResultSafely(fragment, intent, requestCode)  StartActivityDelegate.startActivityForResultSafely(fragment, intent, requestCode, options)  StartActivityDelegate.startActivitySafely(context, intent)  StartActivityDelegate.startActivitySafely(context, intent, options)  StartActivityDelegate.startActivityForResultSafely(activity, intent, requestCode)  StartActivityDelegate.startActivityForResultSafely(activity, intent, requestCode, options)

Dismiss dialog fragment safely

Dismiss a dialog fragment or support v4 dialog fragment safely. dialogFragmentDismissDelegate will dismiss this dialog fragment only when it's resumed, otherwise, it will return true and dismiss it when dialogFragmentDismissDelegate.onResumed is called. Never get activity state loss error again!

dialogFragmentDismissDelegate.safeDismiss(dialogFragment)  dialogFragmentDismissDelegate.onResumed(dialogFragment)  supportDialogFragmentDismissDelegate.safeDismiss(dialogFragment)  supportDialogFragmentDismissDelegate.onResumed(dialogFragment)

Do fragment transaction safely

Do fragment or support v4 fragment transaction safely. Components (activity, fragment or support v4 fragment) should implement the TransactionCommitter interface, and the fragment transaction will only be committed when the components is resumed, otherwise it will return true and the transaction will be committed when onResumed is called. Never get activity state loss error again!

fragmentTransactionDelegate.safeCommit(transactionCommitter, transaction)  fragmentTransactionDelegate.onResumed()  supportFragmentTransactionDelegate.safeCommit(transactionCommitter, transaction)  supportFragmentTransactionDelegate.onResumed()

Build fragment transaction safely

See FragmentTransactionBuilder and SupportFragmentTransactionBuilder.

Just extends the safely base components

We provide the default safely components, including SafelyActivity, SafelyDialogFragment, SafelyFragment, SafelyAppCompatActivity, SafelySupportDialogFragment, and SafelySupportFragment, which encapsulate safely behaviours above, you can just extends them, and dismiss dialog fragment with safeDismiss(), do fragment transaction with safeCommit(transaction), then you can build safely Android app now!

Create your own base components

If your base components must extends other base components, you can make your base component implement the TransactionCommitter interface, and mimic the behaviours of safely base components provided by us, then you can also build safely Android app now!

Lint check

When using safeCommit, lint will warn "Missing commit() calls", you could disable it.

We provide a custom lint rule, to check the "unsafe dismiss() call" of dialog fragment.

Just adding this dependency in your module's build.gradle:

repositories {

  jcenter() 
}
  dependencies {

  compile 'com.github.piasy:safelyandroid-lint:1.2.0' 
}

The suppress of "Missing commit() calls" and "unsafe commit() call" lint rules may not be added in the long future. :(

Resources

Easy to use RecyclerView.

CWAC-Cam2 is an effort to create an in-app ACTION_IMAGE_CAPTURE workalike, with a bit more configurability. You still integrate by opening up a separate activity, but it is all within your own app, rather than relying upon device- or user-specific third-party camera apps.

Easiest way to handle image via camera and gallery intent.

AutoValue + Json Mapper.

AutoValue for ParseObject.

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