Context wrapper openOrclosedatbase exception in Android? -


i creating application in need use broadcast receiver, issue is, can't pass broadcast.this database context.

i tried create activity , used activity.this in database context no use.

please can let me know how use database context in broadcast receiver.

my broadcast receiver here:

 public class broadcastreceiver extends broadcastreceiver { string[] doc_id; folderlist doclistid; dms_database database; context context; final public static string one_time = "onetime"; @override public void onreceive(context context, intent intent)  {        strictmode.threadpolicy policy = new strictmode.threadpolicy.builder().permitall().build();     strictmode.setthreadpolicy(policy);     toast.maketext(context, " alarm received !!! ", toast.length_long).show();     database = new dms_database(context);     list<folderlist> doclist = database.getalldoc();     database.close();     system.out.println(doclist.size());     for(int i=0;i<doclist.size();i++)     {     doclistid = doclist.get(i);     doc_id = new string[doclist.size()];     doc_id[0] = doclistid.getid();     intent idintent = new intent();     idintent.putextra("doc_id", doc_id[0]);     system.out.println(doc_id[0]);     update = new update();     up.updatefile(doc_id[0]);     } } public void cancelalarm(context context) {     intent intent = new intent(context, broadcastreceiver.class);     pendingintent sender = pendingintent.getbroadcast(context, 0, intent, pendingintent.flag_update_current);     alarmmanager alarmmanager = (alarmmanager) context.getsystemservice(context.alarm_service);     alarmmanager.cancel(sender); } public void onlogin(context context){  } public void savealarm(context context) {     alarmmanager alarms = (alarmmanager) context.getsystemservice(context.alarm_service);     intent intent = new intent(context, broadcastreceiver.class); //  intent.putextra(one_time, boolean.false);     pendingintent recurringdownload = pendingintent.getbroadcast(context,             0, intent, pendingintent.flag_update_current);     alarms.setrepeating(alarmmanager.rtc_wakeup, system.currenttimemillis(),             1000 * 10, recurringdownload);   }  //tried make activity in same broadcast receiver, use database context o use public class update extends activity {        string id;     string filelongname;     string userfilename;     string url;     string fileextension;     string lastmodifieddate;     string subjecttype;     boolean isupdated;     dms_database db;     private static final string namespace = "http://tempuri.org/";     private static final string url = "http://192.168.1.5/interlogicsmobile/interlogics.asmx";     private static final string update_file_method = "getdocumentupdatedinfo";     private static final string soap_action_update_file = "http://tempuri.org/getdocumentupdatedinfo";  public void updatefile(string doc_id) {     try     {         soapobject subfolderrequest = new soapobject(namespace, update_file_method);         subfolderrequest.addproperty("documentid", doc_id);         soapserializationenvelope envelope = new soapserializationenvelope(soapenvelope.ver11);         envelope.dotnet = true;         envelope.setoutputsoapobject(subfolderrequest);         httptransportse androidhttptransport = new httptransportse(url);         androidhttptransport.debug = true;         androidhttptransport.call(soap_action_update_file , envelope);         soapobject docresponse = (soapobject)envelope.getresponse();             log.i("uspdated documents", docresponse.tostring());             for(int i=0; < docresponse.getpropertycount(); i++)         {             soapobject singlesubfolder = (soapobject)docresponse.getproperty(i);                     id = singlesubfolder.getproperty(0).tostring();             filelongname = singlesubfolder.getproperty(1).tostring();             userfilename = singlesubfolder.getproperty(2).tostring();             url = singlesubfolder.getproperty(3).tostring();             fileextension = singlesubfolder.getproperty(4).tostring();             lastmodifieddate = singlesubfolder.getproperty(5).tostring();             subjecttype = singlesubfolder.getproperty(6).tostring();             isupdated = singlesubfolder.hasproperty("isupdated");             if(isupdated==true){             db = new dms_database(update.this);             db.update_doc(id, userfilename, url);    //gettig error here & in database update_doc method...             db.close();     } }        catch(exception e)      {         e.printstacktrace();         toast.maketext(this, " network exception : " + e                 + "please check network connectivity.", toast.length_long).show();     } } } } 

try context.getapplicationcontext(), should on new thread.


Comments

Popular posts from this blog

c# - DetailsView in ASP.Net - How to add another column on the side/add a control in each row? -

javascript - firefox memory leak -

Trying to import CSV file to a SQL Server database using asp.net and c# - can't find what I'm missing -