I access a db in an activity that is used in a different activity. However when i use getContentResolver.update() on the db it won't update in my CursorLoader although it accesses the same db (it's the same queryUri). It shows me the updated value when i dump a query to the db, however the CursorLoader won't.
Here is my onCreateLoader method:
#Override
public Loader<Cursor> onCreateLoader(int id, Bundle args) {
Uri queryUri;
if(id == ID_LOADER_PORTFOLIO) {
String[] projection = null;
String selection = null;
String[] selectionArguments = null;
queryUri = MainFeedContract.CONTENT_URI;
return new CursorLoader(this,
queryUri,
MainActivity.COLUMN_NAMES,
selection,
selectionArguments,
null);
}
return null;
}
and this is my call to update the db in the same activity:
portfolioBuilder
.setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
#Override
public void onClick(DialogInterface dialog, int which) {
dialog.cancel();
}
})
.setPositiveButton("Apply",new DialogInterface.OnClickListener() {
#Override
public void onClick(DialogInterface dialog, int which) {
EditText et_newValue = (EditText) view.findViewById(R.id.et_portfolio);
Double value = Double.valueOf(et_newValue.getText().toString());
String selectedSpinnerCurrency = spinner.getSelectedItem().toString();
ContentValues cv = new ContentValues();
cv.put("units",value);
getContentResolver().update(MainFeedContract.CONTENT_URI, cv, "name=?", new String[]{selectedSpinnerCurrency});
Log.d("QUERY", DatabaseUtils.dumpCursorToString(getContentResolver().query(MainFeedContract.CONTENT_URI, null, null, null, null)));
}
});
Am i making a mistake when trying to update the db? :/
You may need to register a ContentObserver
Call this method in onResume()
public void registerDataObserver() {
try {
getContext().getContentResolver().registerContentObserver(MainFeedContract.CONTENT_URI, true, new DataObserver(new Handler()));
} catch (IllegalStateException ise) {
}
}
DataObserver class
class DataObserver extends ContentObserver {
public DataObserver(Handler handler) {
super(handler);
}
#Override
public void onChange(boolean selfChange, Uri uri) {
getLoaderManager().restartLoader(0, null, this);
}
}
Related
I am working on application, that exists Sqlite Database. What I have done to implement the search on sqlite database using list, I have implemented the like query and I came to know; The searchview is not searching data from sqlite...
Here is my Sqlite File....
public List<GetSetClientsDetail> SearchClientsData() {
String[] columns = {
fname,
route,
cnic,
lname,
contact
};
String sortOrder = fname + " ASC";
List<GetSetClientsDetail> clientlist = new ArrayList<GetSetClientsDetail>();
SQLiteDatabase db = this.getReadableDatabase();
Cursor cursor = db.query(
table_poducts_records,
new String[] { fname, route, cnic, lname, contact},
fname + " LIKE '%" + fname + "%'",
null, null, null, null, null);
if (cursor.moveToFirst()) {
do {
GetSetClientsDetail clientsDetail = new GetSetClientsDetail();
clientsDetail.setFNAME(cursor.getString(cursor.getColumnIndex(fname)));
clientsDetail.setROUTE(cursor.getString(cursor.getColumnIndex(route)));
clientsDetail.setCNIC(cursor.getString(cursor.getColumnIndex(cnic)));
clientsDetail.setLNAME(cursor.getString(cursor.getColumnIndex(lname)));
clientsDetail.setCONTACT(cursor.getString(cursor.getColumnIndex(contact)));
clientlist.add(clientsDetail);
} while (cursor.moveToNext());
}
cursor.close();
db.close();
return clientlist;
}
Here is my viewpage class of search where I have implemented search..
public class Clients extends Fragment {
RecyclerView recyclerViewClients;
Button btnAll;
SearchView searchViewclient;
ClientRecyclerAdapter clientRecyclerAdapter;
List<GetSetClientsDetail> listclients;
DatabaseHelper databaseHelper;
#Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.clients, container, false);
btnAll=view.findViewById(R.id.searchallclients);
recyclerViewClients=view.findViewById(R.id.recyclerviewallclients);
searchViewclient=view.findViewById(R.id.searchclient);
listclients = new ArrayList<>();
clientRecyclerAdapter = new ClientRecyclerAdapter(listclients,recyclerViewClients);
recyclerViewClients.setItemAnimator(new DefaultItemAnimator());
recyclerViewClients.setItemAnimator(new DefaultItemAnimator()); //multi copy paste!
recyclerViewClients.setLayoutManager(new LinearLayoutManager(getContext()));
recyclerViewClients.setHasFixedSize(true);
recyclerViewClients.setAdapter(clientRecyclerAdapter);
databaseHelper = new DatabaseHelper(getActivity());
searchViewclient.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
SearchSQliteClientData();
}
});
btnAll.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
getClientFromSqlite();
}
});
return view;
}
#SuppressLint("StaticFieldLeak")
private void SearchSQliteClientData() {
new AsyncTask<Void, Void, Void>() {
#Override
protected Void doInBackground(Void... params) {
listclients.clear();
listclients.addAll(databaseHelper.SearchClientsData());
return null;
}
#Override
protected void onPostExecute(Void aVoid) {
super.onPostExecute(aVoid);
clientRecyclerAdapter.notifyDataSetChanged();
}
}.execute();
}
#SuppressLint("StaticFieldLeak")
private void getClientFromSqlite() {
new AsyncTask<Void, Void, Void>() {
#Override
protected Void doInBackground(Void... params) {
listclients.clear();
listclients.addAll(databaseHelper.getAllClientsData());
return null;
}
#Override
protected void onPostExecute(Void aVoid) {
super.onPostExecute(aVoid);
clientRecyclerAdapter.notifyDataSetChanged();
}
}.execute();
}
}
What I want to do is As I press A on searchview; It brings all data related to a or If I press a letter It bring that data in the list I have Implemented..
As an example
change public List<GetSetClientsDetail> SearchClientsData()
to
public List<GetSetClientsDetail> SearchClientsData(String mysearchstring)
this allows the search argument to be passed to the method from the caller
Then change :-
Cursor cursor = db.query(
table_poducts_records,
new String[] { fname, route, cnic, lname, contact},
fname + " LIKE '%" + fname + "%'",
null, null, null, null, null);
to
String[] whereargs = new String[]{"%" + mysearchstring + "%"}; //<<<<<<<<<< ADDED
Cursor cursor = db.query(
table_poducts_records,
new String[] { fname, route, cnic, lname, contact},
fname + " LIKE ?", //<<<<<<<<<< CHANGED
whereargs, //<<<<<<<<<< ADDED
null, null, null); //<<<<<<<<<< 3 nulls instead of 4 (as whereargs has replaced first null)
this uses the search argument passed to the method in the LIKE clause protecting against SQL Injection
As a test try :-
listclients.addAll(databaseHelper.SearchClientsData("A")); //<<<<<<<<<< look for all with A anywhere in the fname column
Working example
The following is a working example based upon the code in the question but simplified for convenience.
The core change is two fold as, the above code is in the database helper DatabaseHelper.java as per :-
That is the SearchClientData method is :-
public List<GetSetClientsDetail> SearchClientsData(String mysearchstring) {
String[] columns = {
fname, route, cnic, lname, contact
};
String sortOrder = fname + " ASC";
List<GetSetClientsDetail> clientlist = new ArrayList<GetSetClientsDetail>();
SQLiteDatabase db = this.getReadableDatabase();
String[] whereargs = new String[]{"%" + mysearchstring + "%"}; //<<<<<<<<<< ADDED
Cursor cursor = db.query(
table_poducts_records,
new String[]{fname, route, cnic, lname, contact},
fname + " LIKE ?",
whereargs,
null, null, sortOrder, null
);
if (cursor.moveToFirst()) {
do {
GetSetClientsDetail clientsDetail = new GetSetClientsDetail();
clientsDetail.setFNAME(cursor.getString(cursor.getColumnIndex(fname)));
clientsDetail.setROUTE(cursor.getString(cursor.getColumnIndex(route)));
clientsDetail.setCNIC(cursor.getString(cursor.getColumnIndex(cnic)));
clientsDetail.setLNAME(cursor.getString(cursor.getColumnIndex(lname)));
clientsDetail.setCONTACT(cursor.getString(cursor.getColumnIndex(contact)));
clientlist.add(clientsDetail);
} while (cursor.moveToNext());
}
cursor.close();
return clientlist;
}
public List<GetSetClientsDetail> getAllClientsData() {
return SearchClientsData("");
}
Note the freebie getAllClientsData which just uses the SearchClientData method passing "", which will select all rows.
The other core change is that instead of relying upon the SearchView's OnClickListener which may well get called due to the Views other Listener's stealing the focus-ability.
The SearchView's setOnQueryTextListener has been utilised. This allows the text to be passed to the SearchClientsData.
For convenience this example utilises an ArrayAdapter and the stock Simple_List_Item1 layout and does the work on the main thread and of activity.
The Activity code used was :-
public class MainActivity extends AppCompatActivity {
ListView listviewClients;
Button btnAll;
ArrayAdapter mSCA;
SearchView searchViewclient;
List<GetSetClientsDetail> listclients;
DatabaseHelper databaseHelper;
#Override
protected void onCreate(#Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
btnAll=this.findViewById(R.id.searchallclients);
listviewClients=this.findViewById(R.id.clients);
searchViewclient=this.findViewById(R.id.searchclient);
databaseHelper = new DatabaseHelper(this);
addSomeData();
manageListView("");
searchViewclient.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
manageListView("zzz");
}
});
searchViewclient.setOnQueryTextListener(new SearchView.OnQueryTextListener() {
#Override
public boolean onQueryTextSubmit(String query) {
return false;
}
#Override
public boolean onQueryTextChange(String newText) {
manageListView(newText);
return false;
}
});
btnAll.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
manageListView("");
}
});
}
private void manageListView(String searchArgument) {
listclients = databaseHelper.SearchClientsData(searchArgument);
if (mSCA == null) {
mSCA = new ArrayAdapter(this,android.R.layout.simple_list_item_1,listclients);
listviewClients.setAdapter(mSCA);
} else {
mSCA.clear();
mSCA.addAll(listclients);
mSCA.notifyDataSetChanged();
}
}
private void addSomeData() {
databaseHelper.add("Albert","001","123456789","Smith","someone");
databaseHelper.add("Freda","001","123456789","Jones","someone");
databaseHelper.add("Mike","002","0987654321","Allenby","him");
}
/*
private void SearchSQliteClientData() {
new AsyncTask<Void, Void, Void>() {
#Override
protected Void doInBackground(Void... params) {
listclients.clear();
listclients.addAll(databaseHelper.SearchClientsData());
return null;
}
#Override
protected void onPostExecute(Void aVoid) {
super.onPostExecute(aVoid);
clientRecyclerAdapter.notifyDataSetChanged();
}
}.execute();
}
private void getClientFromSqlite() {
new AsyncTask<Void, Void, Void>() {
#Override
protected Void doInBackground(Void... params) {
listclients.clear();
listclients.addAll(databaseHelper.getAllClientsData());
return null;
}
#Override
protected void onPostExecute(Void aVoid) {
super.onPostExecute(aVoid);
clientRecyclerAdapter.notifyDataSetChanged();
}
}.execute();
}
*/
}
The addSomeData method does as it says adds some testing data. The commented out code is original but unused code.
Result
When first run (not really the 1st, rather after a number of runs BUT freshly started, hence plenty of data) :-
Typing a or A and all the Mike's disappear
and so on, the list is instantly adjusted according to the text entered in the search field. Clicking the ALL button re-displays all.
I am using a content observer to know that there is a change made to contact phonebook of the device but I am not getting the exact task done like whether the contact has been added, deleted or updated and what is the value of the modified contact.
// Service running in background which always run and check to know that content has been changed
public class ContactChange extends Service {
ContactObserver observer;
#Nullable
#Override
public IBinder onBind(Intent intent) {
return null;
}
#Override
public void onCreate() {
observer = new ContactObserver(new Handler(),getApplicationContext());
// TODO Auto-generated method stub
getContentResolver().registerContentObserver(ContactsContract.Contacts.CONTENT_URI, false, observer);
super.onCreate();
}
#Override
public void onDestroy() {
super.onDestroy();
getContentResolver().unregisterContentObserver(observer);
}
}
//Content observer where we get to know that changes has made to the contact phonebook
public class ContactObserver extends ContentObserver {
private Context mContext;
DataBaseCurdOperation dataBaseCurdOperation;
ApiInterface apiInterface;
MyPrefs myPrefs;
ArrayList<InviteList> inviteArrayList;
public ContactObserver(Handler handler, Context context) {
super(handler);
this.mContext = context;
dataBaseCurdOperation = new DataBaseCurdOperation(mContext);
myPrefs = new MyPrefs(mContext);
apiInterface = ServiceGenerator.createService(ApiInterface.class, Config.BASE_URL_1);
inviteArrayList = new ArrayList<InviteList>();
}
#Override
public void onChange(boolean selfChange) {
this.onChange(selfChange, null);
}
#Override
public void onChange(boolean selfChange, Uri uri) {
Logger.LogError("URI", uri.toString());
boolean hasContactPermission = (ContextCompat.checkSelfPermission(mContext,
android.Manifest.permission.READ_CONTACTS) == PackageManager.PERMISSION_GRANTED);
if (hasContactPermission) {
SavingContactsActivity savingContactsActivity = new SavingContactsActivity(mContext);
savingContactsActivity.execute();
new InviteApiCall().execute();
}
}
Taking this approach and it is giving the contact whether it is added or updated not got the solution for deleted but surely will post the answer of deleted soon....
And I worked on the database after that
public class ContactSyncObserver extends ContentObserver {
Context mContext;
DataBaseCurdOperation dataBaseCurdOperation;
MyPrefs myPrefs;
public ContactSyncObserver(Handler handler, Context mContext) {
super(handler);
this.mContext = mContext;
dataBaseCurdOperation = new DataBaseCurdOperation(mContext);
myPrefs = new MyPrefs(mContext);
}
#Override
public boolean deliverSelfNotifications() {
return true;
}
#Override
public void onChange(boolean selfChange, Uri uri) {
super.onChange(selfChange, uri);
boolean hasContactPermission = (ContextCompat.checkSelfPermission(mContext,
Manifest.permission.READ_CONTACTS) == PackageManager.PERMISSION_GRANTED);
if (hasContactPermission) {
try {
Cursor cursor = mContext.getContentResolver().query(ContactsContract.Contacts.CONTENT_URI, null, null, null, ContactsContract.Contacts.CONTACT_LAST_UPDATED_TIMESTAMP + " Desc");
if (cursor.moveToNext()) {
String id = cursor.getString(cursor.getColumnIndex(ContactsContract.Contacts._ID));
Logger.LogError("contactId", myPrefs.getContactId());
String name = cursor.getString(
cursor.getColumnIndex(ContactsContract.Contacts.DISPLAY_NAME));
String rawContactId = cursor.getString(cursor.getColumnIndex(ContactsContract.Contacts.NAME_RAW_CONTACT_ID));
String phoneNumber = null;
String hasPhoneNumber = cursor.getString(cursor.getColumnIndex(ContactsContract.Contacts.HAS_PHONE_NUMBER));
if (Integer.parseInt(hasPhoneNumber) > 0) {
Cursor phones = mContext.getContentResolver().query(ContactsContract.CommonDataKinds.Phone.CONTENT_URI, null, ContactsContract.CommonDataKinds.Phone.CONTACT_ID + " = " + id, null, null);
while (phones.moveToNext()) {
phoneNumber = phones.getString(phones.getColumnIndex(ContactsContract.CommonDataKinds.Phone.NUMBER));
Log.e("Number", phoneNumber);
}
phones.close();
}
if (phoneNumber != null) {
phoneNumber = phoneNumber.replaceAll(" ", "");
}
if (dataBaseCurdOperation.checkIsContactIdExist(id)) {
if (!myPrefs.getContactId().equals(id)) {
dataBaseCurdOperation.updateNewNumber(id, phoneNumber, name, "updated");
UtilHandler.TriggerRefresh();
} else {
Handler handler = new Handler();
handler.postDelayed(new Runnable() {
#Override
public void run() {
myPrefs.setContactId("0");
}
}, 3000);
}
} else {
dataBaseCurdOperation.insertServerContact(id, name, phoneNumber, "inserted", "newNumber", "newName");
UtilHandler.TriggerRefresh(); // triggering my sync adapter here...
}
myPrefs.setContactId(id);
}
} catch (Exception e) {
Logger.LogError("Contact Exception", "occured");
}
}
}
}
I am developing an application in which i am working on Android Contacts and not able to move ahead. In app the need of application is that the contact which is updated should send to server or the contact which is deleted should send to server for sync.
I am using the contact service as:
public class ContactService extends Service {
private int mContactCount;
Cursor cursor = null;
static ContentResolver mContentResolver = null;
// Content provider authority
public static final String AUTHORITY = "com.android.contacts";
// Account typek
public static final String ACCOUNT_TYPE = "com.example.myapp.account";
// Account
public static final String ACCOUNT = "myApp";
// Instance fields
Account mAccount;
Bundle settingsBundle;
#Override
public void onCreate() {
super.onCreate();
// Get contact count at start of service
mContactCount = getContactCount();
}
#Override
public int onStartCommand(Intent intent, int flags, int startId) {
// Get contact count at start of service
this.getContentResolver().registerContentObserver(ContactsContract.CommonDataKinds.Phone.CONTENT_URI, true, mObserver);
return Service.START_STICKY;
}
#Override
public IBinder onBind(Intent arg0) {
return null;
}
private int getContactCount() {
try {
cursor = getContentResolver().query(ContactsContract.CommonDataKinds.Phone.CONTENT_URI, null, null, null, null);
if (cursor != null) {
return cursor.getCount();
} else {
cursor.close();
return 0;
}
} catch (Exception ignore) {
} finally {
cursor.close();
}
return 0;
}
private ContentObserver mObserver = new ContentObserver(new Handler()) {
#Override
public void onChange(boolean selfChange) {
this.onChange(selfChange, null);
}
#Override
public void onChange(boolean selfChange, Uri uri) {
new changeInContact().execute();
}
};
public class changeInContact extends AsyncTask<String, Void, String> {
#Override
protected void onPreExecute() {
super.onPreExecute();
}
#Override
protected String doInBackground(String... arg0) {
ArrayList<Integer> arrayListContactID = new ArrayList<Integer>();
int currentCount = getContactCount();
if (currentCount > mContactCount) {
// Contact Added
} else if (currentCount < mContactCount) {
// Delete Contact
} else if (currentCount == mContactCount) {
// Update Contact
}
mContactCount = currentCount;
return "";
}
#Override
protected void onPostExecute(String result) {
contactService = false;
} // End of post
}
}
The issues i am facing are as follows :
A: In the above code for getting the recently updated contact i need to check the Version of each contact from device with my database stored version of contacts. Which took much time for large amount of contacts.
B. For getting deleted contact i need to check that the data for the Raw id stored in my database is present in device or not. If not then the contact is deleted. It also take too much time to check whole contacts.
But the same thing contact refresh is done in whats app in very few seconds like 2 to three seconds...
EDIT :
In the above code in following module :
if (currentCount > mContactCount) {
// Contact Added
Log.d("In","Add");
} else if (currentCount < mContactCount) {
// Delete Contact
Log.d("In","Delete");
} else if (currentCount == mContactCount) {
// Update Contact
Log.d("In","Update");
}
I put the log. So the update module is called many times, and also when i do add or delete that time too...
Please guide me and suggest me what to do to reduce the timing for the above tasks...
use the below query to get all the deleted and updated contacts.
public static final String ACCOUNT_TYPE = "com.android.account.youraccounttype"
public static final String WHERE_MODIFIED = "( "+RawContacts.DELETED + "=1 OR "+
RawContacts.DIRTY + "=1 ) AND "+RawContacts.ACCOUNT_TYPE+" = '"+ ACCOUNT_TYPE+"'";
c = contentResolver.query(ContactsContract.RawContacts.CONTENT_URI,
null,
WHERE_MODIFIED,
null,
null);
I have created contact change observer, when a user any time change their contact need to know what change they did.
Step 1 :
public class ContactChangeObserver extends ContentObserver {
Context mContext;
public ContactChangeObserver(Handler handler, Context ctx) {
super(handler);
mContext = ctx;
}
#Override
public boolean deliverSelfNotifications() {
return super.deliverSelfNotifications();
}
#Override
public void onChange(boolean selfChange) {
super.onChange(selfChange);
Log.e("Content Change", "Added New onChange selfChange");
}
#Override
public void onChange(boolean selfChange, Uri uri) {
Log.e("NoOf Content Change", "Contant Change Happen");
super.onChange(selfChange, uri);
if(mContext != null) {
Log.e("Content Change Name :", "start checking");
AppPreferences appPreferences = new AppPreferences(mContext);
String[] projection = {
ContactsContract.CommonDataKinds.Phone.DISPLAY_NAME,
ContactsContract.CommonDataKinds.Phone.NUMBER
};
Cursor cursor = mContext.getContentResolver().query(uri, projection, null, null, null);
if (cursor.moveToFirst()) {
String sender = cursor.getString(cursor.getColumnIndex(ContactsContract.CommonDataKinds.Phone.DISPLAY_NAME));
String mobileno = cursor.getString(cursor.getColumnIndex(ContactsContract.CommonDataKinds.Phone.NUMBER));
String status = "phone";
MaraContactsManager.getInstance().updateContactDB(mContext, mobileno, sender, status, appPreferences.getCountryCode());
}
}
}
Step 2: have register this by calling at HomeActivity
contactChangeObserver = new ContactChangeObserver(new Handler(),getApplicationContext());
getApplicationContext().getContentResolver().registerContentObserver(ContactsContract.Contacts.CONTENT_URI, true, contactChangeObserver);
Step 3: when i change any contact it goes to onChange Methode but I am not getting which contact changes done it says
java.lang.IllegalArgumentException: URI: content://com.android.contacts, calling user:
Please Help
I have a fully functional SQLite database in my Android App which works perfect on my testing devices (Android 4.0 - 4.3), but I have a user running KitKat and they are unable to update the database. To summarize my code, I have a user click a switch, then asks whether they want to make the change, if so it updates the database table.
Here is my calls to the database from the Activity:
StatusData statusData;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_macro);
statusData = new StatusData(getBaseContext());
}
#Override
public void onClick(View v) {
AlertDialog.Builder alertDialogBuilder;
AlertDialog alertDialog;
switch (v.getId())
case R.id.switchOffSeason:
String season,
seasonHeading = "";
alertDialogBuilder = new AlertDialog.Builder(this);
// set dialog message
if (switchOffSeason.isChecked()) {
season = "This will delete all your current settings and default to the standard diet. This cannot be undone";
seasonHeading = "Set Standard Diet";
} else {
season = "This will delete all your current settings and default to Off-Season diet. This cannot be undone.";
seasonHeading = "Set Off-Season Diet";
}
// set title
alertDialogBuilder.setTitle(seasonHeading);
alertDialogBuilder
.setMessage(season)
.setCancelable(false)
.setPositiveButton("Ok",
new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog,
int id) {
String passedTask = "offSeason";
dropTable task = new dropTable(passedTask);
task.execute(passedTask);
}
})
.setNegativeButton("Cancel",
new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog,
int id) {
if (switchOffSeason.isChecked()) {
switchOffSeason.setChecked(false);
} else {
switchOffSeason.setChecked(true);
}
dialog.cancel();
}
});
alertDialog = alertDialogBuilder.create();
private class dropTable extends AsyncTask<String, Void, String> {
String task;
public dropTable(String passedTask) {
super();
task = passedTask;
}
#Override
protected String doInBackground(String... params) {
if (task.equals("reset")) {
String offSeason = statusData.profileTable()[10];
profileTable = statusData.profileTable();
statusData.dropReloadMacrosTable(new String[] {
profileTable[11], profileTable[12], profileTable[13],
profileTable[14], profileTable[15], profileTable[16],
profileTable[17], offSeason });
} else if (task.equals("offSeason")) {
if (switchOffSeason.isChecked()) {
statusData.updateFieldProfile(new String[] { "offseason",
"1" });
} else {
statusData.updateFieldProfile(new String[] { "offseason",
"0" });
}
String offSeason = statusData.profileTable()[10];
statusData.dropReloadMacrosTable(new String[] {
profileTable[11], profileTable[12], profileTable[13],
profileTable[14], profileTable[15], profileTable[16],
profileTable[17], offSeason });
}
return "Executed";
}
Here is my StatusData (Database) class:
public void updateFieldProfile(String updateArray[]) {
open();
Log.i("log", "in method");
String fieldToUpdate = updateArray[0];
String valueToUpdate = updateArray[1];
String query = "UPDATE PROFILE SET " + fieldToUpdate + "="
+ "= ?";
Log.i("logQuery", query);
Cursor c = db.rawQuery(query, new String[] {valueToUpdate});
c.moveToFirst();
c.close();
db.close();
}