Rarity7-
Rarity7-

Reputation: 187

How to get argument from constructor?

class AlmatyJobViewModel(application: Application) : AndroidViewModel(application){   

 fun clearSuggestionsHistory(){
            SearchRecentSuggestions(application, MySuggestionsProvider.AUTHORITY, MySuggestionsProvider.MODE)
                .clearHistory()
        }
}

Unresolved Referense: application

How to get application from constructor, if i want to use it in this method?

Upvotes: 2

Views: 103

Answers (1)

Julio Lemus
Julio Lemus

Reputation: 661

If you add private val application you will have exceptions in compilation time like

Accidental override: The following declarations have the same JVM signature

So, to fix it, you only should to call getApplication() where you require.

SearchRecentSuggestions(getApplication(), MySuggestionsProvider.AUTHORITY, MySuggestionsProvider.MODE).clearHistory()

Upvotes: 3

Related Questions