I have following class with a constructor :
public class TestAdapter {
protected static final String TAG = "DataAdapter";
private final Context mContext;
private SQLiteDatabase mDb;
private DatabaseHandler mDbHelper;
// private static SQLiteDatabase mDb2;
// private static DatabaseHandler mDbHelper2;
public TestAdapter(Context context) {
this.mContext = context;
mDbHelper = new DatabaseHandler(mContext);
}
In this very class I have a setFlag() method which I need to call from following method –
@Override
protected void onPostExecute(String result) {
// tv.setText(result);
Log.e("result", result);
if (Integer.parseInt(result) == 1) {
flagValue = 1;
Log.e("my","flag value set");
//TestAdapter t =new TestAdapter();
//setFlag()
}
the commented part is where I need to call that method but I don’t know how to create object of the “TestAdapter” class. If I make setFlag() static in that class, then other instances being used in that method will not work because they are not static. F1 F1 F1
EDIT: I am given to understand that context exist for an activity but this class in which I need to create the object is not an activity..its just a java class which has methods to sync local database with server database.
First declare in your Activity first declare on top
Context context = null;Then in onCreate
context = this;.Now you can use your method like:
TestAdapter t = new TestAdapter(context); t.setFlag();