android - Context for getDefaultSharedPreferences() in database function file -


i have file, have functions database , 1 query need preferences getdefaultsharedpreferences(), don’t know how can context easily.

here fragment of file:

public class database {      private sqliteopenhelper openhelper;      public cursor getvzkazy(long uzivatel) {         sqlitedatabase db = openhelper.getreadabledatabase();         int limit = preferencemanager.getdefaultsharedpreferences(this).getint("limit", 100000);         return db.query(tb_name_vz, columns_vz, null, null, null, null, column_id_vz + " desc", string.valueof(limit));     } } 

you'll need pass context when instantiating the database class. add public constructor class database:

public class database {      private context mcontext;      public database(context context) {         mcontext = context;     } } 

then use mcontext, passing "this" won't work it's of type database , expects type context, that'll produce compilation error.


Comments

Popular posts from this blog

html - Sizing a high-res image (~8MB) to display entirely in a small div (circular, diameter 100px) -

java - IntelliJ - No such instance method -

identifier - Is it possible for an html5 document to have two ids? -