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

php - regexp cyrillic filename not matches -

c# - OpenXML hanging while writing elements -

sql - Select Query has unexpected multiple records (MS Access) -