Get parent Activity from View #363
Comments
I don't think we want to violate the scoping of views with this. Would we also have one for |
@trent-dev Are you getting this from the Android code base? Such as |
@jaredsburrows Yes. I found it from somewhere similar to code you linked. |
We have the following extension in our code:
I'm not super happy with the IllegalArgumentException but in our case it should never happen. |
That is needlessly recursive.
I still remain unconvinced we should be promoting this.
…On Fri, Mar 2, 2018 at 1:06 PM Philip Schiffer ***@***.***> wrote:
We have the following extension in our code:
fun Context.getActivityContext(): Activity = when (this) {
is Activity -> this
is ContextWrapper -> this.baseContext.getActivityContext()
else -> throw IllegalArgumentException("Not an activity context")
}
I'm not super happy with the IllegalArgumentException but in our case it
should never happen.
—
You are receiving this because you commented.
Reply to this email directly, view it on GitHub
<#363 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/AAEEEdA9cBZlU8j8n6J-MVY8k2md8r5vks5taYoFgaJpZM4SUure>
.
|
@JakeWharton Good point, a "tailrec" should fix that, right? I also get your point, it is not always safe to use. |
It might! Worth a try.
…On Fri, Mar 2, 2018 at 1:11 PM Philip Schiffer ***@***.***> wrote:
@JakeWharton <https://github.com/jakewharton> Good point, a "tailrec"
should fix that, right? I also get your point, it is not always safe to use.
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#363 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/AAEEEVGSdSGLPrqclkjSccURiVwPiEgAks5taYtcgaJpZM4SUure>
.
|
Going to close this because we don't want to recommend this as a general pattern. You should very rarely need to do this, but if you do it's fine to keep the code in your codebase only. |
@JakeWharton We should make a note to deprecate then remove methods in AOSP. |
They're not public.
…On Fri, Mar 2, 2018 at 1:43 PM Jared Burrows ***@***.***> wrote:
@JakeWharton <https://github.com/jakewharton> We should make a note to
deprecate then remove methods in AOSP.
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#363 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/AAEEEW7i9K-zFd6Y3Vlmil41cxa0YcLSks5taZK8gaJpZM4SUure>
.
|
@JakeWharton Good. |
I find this immensely useful when using MVVM pattern.
Please let me know what you think of it. Thanks.
The text was updated successfully, but these errors were encountered: