How is context used in a class usage? -


the line of code giving me fits is:

this.databasehandler = new databasehandler(mainactivity. 

i have module in project , line project trying incorporate. believe need line , having trouble getting idea of context parameter used here. yes, line incomplete because can not finish it. whole structure or thinking wrong?

import android.app.activity; import android.content.context; import android.os.bundle; import android.os.asynctask;   import com.table.tablemainlayout; import com.example.tablefreezepane.databasehandler;  public class mainactivity extends activity {  final string tag = "mainactivity.java";  @override protected void oncreate(bundle savedinstancestate) {     super.oncreate(savedinstancestate);     /* loads next module */     setcontentview(new tablemainlayout(this)); } } public class asyncinsertdata extends asynctask<string, string, string> {  databasehandler databasehandler; string type; long timeelapsed;  protected asyncinsertdata(string type){     this.type  = type;     this.databasehandler = new databasehandler(mainactivity.      //(mainactivity.this); }  // @type - can 'normal' or 'fast' //@override //protected void onpreexecute() { //    super.onpreexecute(); //    tvstatus.settext("inserting " + edittextrecordnum.gettext() + " records..."); //}  @override protected string doinbackground(string... aurl) {      try {          // number of records inserted         int insertcount = 20;          // empty table         databasehandler.deleterecords();          // keep track of execution time         long lstarttime = system.nanotime();          if (type.equals("normal")) {             databasehandler.insertnormal(insertcount);         } else {             databasehandler.insertfast(insertcount);         }          // execution finised         long lendtime = system.nanotime();          // display execution time         timeelapsed = lendtime - lstarttime;      } catch (exception e) {         e.printstacktrace();     }     return null; }  protected void onpostexecute(string unused) {     //toast.maketext(getapplicationcontext(),"this android toast message", toast.length_long).show();     //tvstatus.settext("done " + choice + " inserting " + databasehandler.countrecords() + " records table: [" + this.databasehandler.tablename + "]. time elapsed: " + timeelapsed / 1000000 + " ms."); } 

}

thank in advance.

where async, can't access context mainactivity way are. so, add constructor context parameter, replace mainactivity.this context


Comments

Popular posts from this blog

c++ - Delete matches in OpenCV (Keypoints and descriptors) -

java - Could not locate OpenAL library -

sorting - opencl Bitonic sort with 64 bits keys -