Created
March 12, 2021 10:47
-
-
Save shibbirweb/d6c08eafa7f75a7702e7029424c79fb0 to your computer and use it in GitHub Desktop.
Android: Context to activity
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| package me.shibbir.utils.helpers | |
| import android.app.Activity | |
| import android.content.Context | |
| import android.content.ContextWrapper | |
| object ActivityHelper { | |
| /** | |
| * Get activity | |
| */ | |
| fun contextToActivity(context: Context): Activity? { | |
| if (context is ContextWrapper) { | |
| if (context is Activity) { | |
| return context | |
| } else { | |
| contextToActivity(context.baseContext) | |
| } | |
| } | |
| return null | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment