TheActivityManager


Source link: https://github.com/yayaa/TheActivityManager

TheActivityManager

Tested with Leak Canary

Android OS starts activities up to intents you send as a broadcast, but because it is done privately, you cannot track those activities. You may never know which activity is currently visible, unless you work around somehow. This library will provide you to manage that.

This library uses a singleton class to create a static object and keep instances of your activities. So, you can reach them out whenever you want, and do whatever you wish.

Configuration

To use this library, you need to notify TheActivityManager onCreate, onResume, onPause and onDestroy of activity.

You can call these methods by yourself in every activity that you create

OR

To simplify this step i created a TAMBaseActiviy, which extends from AppCompatActivity, so just extend your activities from this and it will take care of the rest.

OR

if your application's minSdkVersion >= 14 then you can simply call TheActivityManager.getInstance().configure(application) and it will handle all.

CAUTION: If you call configure method, you MUST call it only once, and you MUST NOT extend your activities from TAMBaseActiviy otherwise it will create multiple instance in TheActivityManager array, which may cause crash!

Usage

TheActivityManager.getInstance().getCurrentActivity();
 
  • This method basically return the instance of current activity and you can use it to compare with something or display dialog, popup or whatever you wish, you can call any method on that activity now. This will provide you to access almost every activity.
TheActivityManager.getInstance().isApplicationRunning();
  
  • You can check whether application is currently running or it's been paused for some reason. For instance, you have a service to download something and when it is completed you can just check whether user is still using the application or not, you can have different ways to go.
TheActivityManager.getInstance().finishAll();
  
  • It doesn't matter how deeply you are in the application, this method will finish all of activities and will quit application.
TheActivityManager.getInstance().toLanding();
  
  • It doesn't matter how deeply you were visiting detail pages on application, this method will turn you back to landing page which you should set first by calling `setAsLanding` method otherwise it will just act like `finishAll` method.
TheActivityManager.getInstance().setNextStep(activityTransporter);
  
  • Let's assume that you have Activity A and C but before you go to C you need to do something in Activity B. So you tell TheActivityManager that C is your nextStep with the extras if necessary and when you done with B just call moveForward method and TheActivityManager will lead user to that acitivity with already given extras.

Download

Add library dependency to your build.gradle file:

dependencies {

 compile 'com.yayandroid:TheActivityManager:1.0.6' 
}

Name Story

I thought to name it as ActivityManager but didn't want it to be confused with Android's ActivityManager and than my friend remind me John Carmack's tweet and it was just perfect fit, so it became "TheActivityManager".

I have moved to naming global singletons with a The* prefix -- ThePacketServer, TheMasterServer, TheVoip, etc. Feels pretty good.

— John Carmack (@ID_AA_Carmack) 11 Mart 2015
<script async src="//platform.twitter.com/widgets.js" charset="utf-8"></script>

Compatibility

This library works on 2.2+ probably earlier as well, but i didn't even bother to test because i believe at some point we have to stop supporting every version ;)

License

The MIT License (MIT)  Copyright (c) 2015 yayandroid  Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:  The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 

Resources

Dynamic GridView using Kotlin Language
A small Android library allowing you to have a smooth and customizable circular ProgressBar.
An Android library written in kotlin to display steps in a progress bar using a single view
Gif images loading indicator
A Round ImageView that works with vectors!
Toastest is a library for customizing toasts.

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