All Projects → florent37 → Applicationprovider

florent37 / Applicationprovider

Licence: apache-2.0
Retrieve the android application and the current activity from anywhere

Programming Languages

java
68154 projects - #9 most used programming language
kotlin
9241 projects

Projects that are alternatives of or similar to Applicationprovider

Timber Ruby
🌲 Great Ruby logging made easy.
Stars: ✭ 154 (-4.94%)
Mutual labels:  application, context
Android Architecture
🌇该项目结合 MVP 与 Clean 架构思想,探索在 Android 项目上的最佳实践。
Stars: ✭ 112 (-30.86%)
Mutual labels:  application, dagger
timber-ruby
🌲 Great Ruby logging made easy.
Stars: ✭ 155 (-4.32%)
Mutual labels:  application, context
Reactjs Authentication Tutorial
Chuck Norris World App - A sample app that shows how to add authentication to a ReactJS app
Stars: ✭ 139 (-14.2%)
Mutual labels:  application
Translateapp
📝 A translations app without interruptions, copy words and translate directly, show result by top view.
Stars: ✭ 1,722 (+962.96%)
Mutual labels:  dagger
Flappy Fly Bird
🐦 Flappy Bird reincarnation [Swift 5.3, GameplayKit, SpriteKit, iOS 12].
Stars: ✭ 150 (-7.41%)
Mutual labels:  application
Coinverse
Coinverse Open App is the first audiocast app for cryptocurrency news. 🚀
Stars: ✭ 133 (-17.9%)
Mutual labels:  dagger
Dotzu
📱👀 In-App iOS Debugging Tool With Enhanced Logging, Networking Info, Crash reporting And More.
Stars: ✭ 1,802 (+1012.35%)
Mutual labels:  application
Powerswitcher
Power plan switcher for Windows 10. Heavily inspired by EarTrumpet.
Stars: ✭ 143 (-11.73%)
Mutual labels:  application
React Af
Allows you to code using certain React.next features today! Perfect for component library maintainers.
Stars: ✭ 143 (-11.73%)
Mutual labels:  context
Hiboot
hiboot is a high performance web and cli application framework with dependency injection support
Stars: ✭ 150 (-7.41%)
Mutual labels:  application
Real Time Ml Project
A curated list of applied machine learning and data science notebooks and libraries across different industries.
Stars: ✭ 143 (-11.73%)
Mutual labels:  application
Contextism
😍 Use React Context better.
Stars: ✭ 141 (-12.96%)
Mutual labels:  context
Dagger
Dagger 是一个基于 Loki 的日志查询和管理系统,它是由达闼科技( CloudMinds )云团队的`大禹基础设施平台`派生出来的一个项目。Dagger 运行在 Loki 前端,具备日志查询、搜索,保存和下载等特性,适用于云原生场景下的容器日志管理场景。
Stars: ✭ 149 (-8.02%)
Mutual labels:  dagger
Corelocationcli
Command line program to print location information from CoreLocation
Stars: ✭ 138 (-14.81%)
Mutual labels:  application
Vue Django Rest Auth
An example project featuring Vue.js and Django Rest Framework using django-rest-auth
Stars: ✭ 153 (-5.56%)
Mutual labels:  application
Pony Stable
🐴 A simple dependency manager for the Pony language.
Stars: ✭ 135 (-16.67%)
Mutual labels:  application
Platypus
Create native Mac applications from command line scripts.
Stars: ✭ 1,893 (+1068.52%)
Mutual labels:  application
App Dirs Rs
Put your Rust app's data in the right place on every platform
Stars: ✭ 147 (-9.26%)
Mutual labels:  application
Workoutwotch
Repository for my video series on building an iOS app in .NET.
Stars: ✭ 156 (-3.7%)
Mutual labels:  application

ApplicationProvider

Retrieve the android application from anywhere

Useful to develop a standalone library

//from anywhere
val application = ApplicationProvider.application

Retrieve the current activity from anywhere

//from anywhere
val currentActivity : Activity? = ActivityProvider.currentActivity()

Or safety from a kotlin coroutine context :

launch {
    val currentActivity = ActivityProvider.activity() //cannot be null
    Log.d(TAG, "activity : $currentActivity")
}

Listen for current activity

launch {
    ActivityProvider.listenCurrentActivity().collect {
        Log.d(TAG, "activity : $currentActivity")
    }
}

Providers

If you need to execute a code automatically when the application starts, without adding it into your application's class code

Create a class that extends Provider

class StethoProvider : Provider() {
    override fun provide() {
        val application = ApplicationProvider.application //if you need the application context
        Stetho.initializeWithDefaults(application)
    }
}

Add it into your manifest

<provider
     android:name=".StethoProvider"
     android:authorities="${applicationId}.StethoInitializer" />

Download

Buy Me a Coffee at ko-fi.com

Download

dependencies {
    implementation 'com.github.florent37:applicationprovider:(lastest version)'
}

Initializers

You do not need to override the Application now

Before

class MyApplication : Application() {
    override fun onCreate(){
        Stetho.initializeWithDefaults(application)
    }
}

After

Using a provider (for libraries)

Note that you can include it directly on your library's aar

class StethoInitializer : ProviderInitializer() {
    override fun initialize(): (Application) -> Unit = {
        Stetho.initializeWithDefaults(application)
    }
}
<provider
     android:name=".timber.TimberInitializer"
     android:authorities="${applicationId}.StethoInitializer" />

Using an initializer

Another way using Initializer

val InitializeStetho by lazy {
    ApplicationProvider.listen { application ->
        Stetho.initializeWithDefaults(application)
    }
}

class MainActivity : AppCompatActivity() {

    init {
        InitializeStetho
    }

    override fun onCreate(savedInstanceState: Bundle?) {
    ...
    }
}
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].