I have a neat, working SQLite database on Android that records species observations. I am then using JSON (successfully) to verify observations entered against a set of parameters on a remote database. On verification, a flag in the database is updated to say that this process has been done. But, when I view my main activity (Text, the values for observations with flags after verification don't update.
My activity order is:
- Main activity (obs = 0 from database)
- Obs Entry activity
- Main activity (obs = 1 with flag A from db)
- Data management activity, verify button
- Verify done activity, main button
- Main activity (obs = 1 with flag A from db)
If I exit, or leave it for a while, then come back in to Main activity, the database is being polled correctly and obs = 1 with flag B from db.
So I know my database is right and the SQL is correct too. Could it be that I'm declaring my buttons at the wrong point for the Activity to correctly resume()?
My code:
final Button verifySightingsButton = (Button) findViewById(R.id.uploadprocess);
if (verifies == 0) {
verifySightingsButton.setTextColor(getResources().getColor(R.color.red));
} else {
verifySightingsButton.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
// do stuff
}
});
}
where 'verifies' is the number of flag A records. The button is being called with the onCreate()
method. Would it make any difference if I instantiated it as a class variable? Thanks in advance - bugging me senseless!
UPDATE: This is the code (actually using XML, not JSON which is used for other queries) that handles the verification and update of flag:
// Get details for an observation within loop
ArrayList d = (ArrayList) allVerifyRows.get(i);
// Build the URL to verify the data
String aURL = buildVerifyURL(d);
// Parse the XML
aValid = ParseVerificationXML.verifyXMLdata(aURL);
db.open();
Long bouCode = new Long((String) speciesList.get((String) d.get(3)));
boolean insert = db.updateNote(
((Long) d.get(0)).longValue(),
((Long) d.get(1)).longValue(),
// and some other variables being updated
db.close();
and the code to check the database for records that are and are not verified:
NotesDbAdapter db = new NotesDbAdapter(this);
db.open();
Cursor c = db.fetchAllNotes();
species = new ArrayList<String>();
while (c.moveToNext()) {
String str1 = c.getString(2); // Date
species.add(str1);
}
c.close();
Cursor v = db.performNullCountForVerification();
if (v.moveToFirst()) {
stillToVerify = v.getInt(0); // Non-Verified records
readyForUpload = stillToVerify;
}
v.close();
stillToVerify = species.size() - stillToVerify;
db.close();
You might use the onResume method of your main activity to update the shown values. The onResume method is called every time the activity appears on the screen in contrast to onCreate, which is only called when the activity gets created.
ReplyDelete