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

[韓日関係] 首相含む大幅な内閣改造の可能性…早ければ来月10日ごろ=韓国

div not scrolling properly with slimScroll plugin

I am using the slimScroll plugin for jQuery by Piotr Rochala Which is a great plugin for nice scrollbars on most browsers but I am stuck because I am using it for a chat box and whenever the user appends new text to the boxit does scroll using the .scrollTop() method however the plugin's scrollbar doesnt scroll with it and when the user wants to look though the chat history it will start scrolling from near the top. I have made a quick demo of my situation http://jsfiddle.net/DY9CT/2/ Does anyone know how to solve this problem?

Why does this javascript based printing cause Safari to refresh the page?

The page I am working on has a javascript function executed to print parts of the page. For some reason, printing in Safari, causes the window to somehow update. I say somehow, because it does not really refresh as in reload the page, but rather it starts the "rendering" of the page from start, i.e. scroll to top, flash animations start from 0, and so forth. The effect is reproduced by this fiddle: http://jsfiddle.net/fYmnB/ Clicking the print button and finishing or cancelling a print in Safari causes the screen to "go white" for a sec, which in my real website manifests itself as something "like" a reload. While running print button with, let's say, Firefox, just opens and closes the print dialogue without affecting the fiddle page in any way. Is there something with my way of calling the browsers print method that causes this, or how can it be explained - and preferably, avoided? P.S.: On my real site the same occurs with Chrome. In the ex