# Access application context in companion object in kotlin

**URL:** <https://discuss.kotlinlang.org/t/access-application-context-in-companion-object-in-kotlin/11054>\
**Category:** Android\
**Created:** [January 7, 2019, 1:35pm UTC](https://discuss.kotlinlang.org/t/access-application-context-in-companion-object-in-kotlin/11054 "2019-01-07T13:35:38Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![hafizhamza](https://avatars.discourse-cdn.com/v4/letter/h/e274bd/32.png) [@hafizhamza](https://discuss.kotlinlang.org/u/hafizhamza)\
**Post date:** [January 7, 2019, 1:35pm UTC](https://discuss.kotlinlang.org/t/access-application-context-in-companion-object-in-kotlin/11054/1 "2019-01-07T13:35:38Z")

</div>

How can we access application context inside companion object in Android kotlin?

---

<div class="post-metadata">

**Author:** ![fatjoe79](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.kotlinlang.org/fatjoe79/32/4221_2.png) [@fatjoe79](https://discuss.kotlinlang.org/u/fatjoe79)\
**Post date:** [January 7, 2019, 2:48pm UTC](https://discuss.kotlinlang.org/t/access-application-context-in-companion-object-in-kotlin/11054/2 "2019-01-07T14:48:10Z")

</div>

You can not. Your options are:

A) Provide the context as an argument to all functions that need it.

B) Instead of a Singleton companion object, create an instance of the class and provide the context as a constructor argument. Consider closing / cleaning up the instance, when not used anymore.

C) When your Application is initialized, store the application context in a globally accessible variable / property. This is arguably the most dirty solution.
