Search code examples
javaandroidsharedpreferencestinydb

TinyDB problem, cannot resolve symbol 'context'


I want to use TinyDB in my Android app that built in Android Studio. To use the TinyDB, I need to add TinyDB class and write the context.

The context that need to be in the MainActivity: TinyDB tinydb = new TinyDB(context); And it shows "Cannot resolve symbol 'context'"

Context part in TinyDB class:

public TinyDB(Context appContext){
    preferences = PreferenceManager.getDefaultSharedPrefeences(appContext);
    context = appContext;
}

Should I replace 'context' with something else?


Solution

  • In Activity, the Context is Activity itself (=this):

    TinyDB tinydb = new TinyDB(this);