Search code examples
androidkotlinretrofitokhttp

how to make api request call on Application class on Kotlin


I need to get a data from an endpoint at begin of my app. I don't know if this is the best practice or not. But I need get it before app's started.

I didnt a suggestion or solution on web


Solution

  • I think you can create a class extend Application class and call request on oncreate function.

    class YourApplication : Application() {
    
        override fun onCreate() {
            super.onCreate()
            // load data
        }
    }
    

    in mainfest application tag please add : android:name=".YourApplication"