Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/kdroidfilter/androidcontextprovider
Android Context Provider is a simple utility library that allows you to easily access the application context from anywhere in your app. This can be especially useful for situations where accessing the context in a static manner is needed.
https://github.com/kdroidfilter/androidcontextprovider
android android-contentprovider android-library android-utilities android-utility android-utils android-utils-library context kotlin-android
Last synced: about 2 months ago
JSON representation
Android Context Provider is a simple utility library that allows you to easily access the application context from anywhere in your app. This can be especially useful for situations where accessing the context in a static manner is needed.
- Host: GitHub
- URL: https://github.com/kdroidfilter/androidcontextprovider
- Owner: kdroidFilter
- License: mit
- Created: 2024-11-06T05:24:16.000Z (3 months ago)
- Default Branch: master
- Last Pushed: 2024-12-08T21:26:30.000Z (2 months ago)
- Last Synced: 2024-12-08T22:26:45.033Z (2 months ago)
- Topics: android, android-contentprovider, android-library, android-utilities, android-utility, android-utils, android-utils-library, context, kotlin-android
- Language: Kotlin
- Homepage: https://central.sonatype.com/artifact/io.github.kdroidfilter/androidcontextprovider
- Size: 114 KB
- Stars: 4
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# 🔧 Android Context Provider
Android Context Provider is a simple utility library that allows you to easily access the application context from anywhere in your app. This can be especially useful for situations where accessing the context in a static manner is needed.
## ✨ Features
- 🛠️ Uses 0 dependencies, making it lightweight and easy to integrate.
- 💪 Easy initialization with your application context.
- 🎮 Access the application context from any part of your code.
## 📃 Getting Started
### 🔍 Installation
The library is available on Maven Central.
To import it into your project, add the following to your `build.gradle.kts` file:
```kotlin
implementation("io.github.kdroidfilter:androidcontextprovider:1.0.1")
```or in Groovy :
```groovy
implementation 'io.github.kdroidfilter:androidcontextprovider:1.0.1'
```### ⏳ Usage
1. **✨ Automatic Initialization**
The `ContextProvider` is automatically initialized using a `ContentProvider`, which means you do not need to explicitly initialize it in your `Application` class. This reduces boilerplate and ensures that the `ContextProvider` is ready to use as soon as your app launches.2. **🔎 Getting the Context**
You can access the application context (not an activity context) from anywhere in your app like this:
```kotlin
val context = ContextProvider.getContext()
// Use the context as needed
```
or in Java :
```java
Context context = ContextProvider.getContext();
// Use the context as needed
```### ⚠️ Important Notes
- **Automatic Initialization**: The `ContextProvider` is initialized automatically via `ContentProvider`, eliminating the need for manual setup.
- **Error Handling**: If you try to get the context before it is initialized, `ContextProvider` will throw an `IllegalStateException`. However, with automatic initialization, this scenario is unlikely.## 📚 License
This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.
## 🌐 Contributions
Contributions are welcome! If you find any issues or have improvements to suggest, feel free to open an issue or a pull request on GitHub.