Skip to main content

SQLite and Activity updates



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();




Comments

  1. 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

Post a Comment

Popular posts from this blog

Why is this Javascript much *slower* than its jQuery equivalent?

I have a HTML list of about 500 items and a "filter" box above it. I started by using jQuery to filter the list when I typed a letter (timing code added later): $('#filter').keyup( function() { var jqStart = (new Date).getTime(); var search = $(this).val().toLowerCase(); var $list = $('ul.ablist > li'); $list.each( function() { if ( $(this).text().toLowerCase().indexOf(search) === -1 ) $(this).hide(); else $(this).show(); } ); console.log('Time: ' + ((new Date).getTime() - jqStart)); } ); However, there was a couple of seconds delay after typing each letter (particularly the first letter). So I thought it may be slightly quicker if I used plain Javascript (I read recently that jQuery's each function is particularly slow). Here's my JS equivalent: document.getElementById('filter').addEventListener( 'keyup', function () { var jsStart = (new Date).getTime()...

Is it possible to have IF statement in an Echo statement in PHP

Thanks in advance. I did look at the other questions/answers that were similar and didn't find exactly what I was looking for. I'm trying to do this, am I on the right path? echo " <div id='tabs-".$match."'> <textarea id='".$match."' name='".$match."'>". if ($COLUMN_NAME === $match) { echo $FIELD_WITH_COLUMN_NAME; } else { } ."</textarea> <script type='text/javascript'> CKEDITOR.replace( '".$match."' ); </script> </div>"; I am getting the following error message in the browser: Parse error: syntax error, unexpected T_IF Please let me know if this is the right way to go about nesting an IF statement inside an echo. Thank you.