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
When dealing with ListActivities, this issue has to do with the Cursor objects, CursorAdapter objects, and Database objects not being closed properly when the Activity stops, and not being set properly when the Activity starts or resumes.
ReplyDeleteI had to make sure that I closed my SimpleListAdapter, my Cursors, and then my Database objects in that respective order, in the onStop method of the Activity that is called when the TabActivity resumes.
I had already been closing the Cursor and Database objects, but had not been closing my SimpleListAdapter Cursor.
/**
* onStop method
*
* Perform actions when the Activity is hidden from view
*
* @return void
*
*/
@Override
protected void onStop() {
try {
super.onStop();
if (this.mySimpleListAdapterObj !=null){
this.mySimpleListAdapterObj.getCursor().close();
this.mySimpleListAdapterObj= null;
}
if (this.mActivityListCursorObj != null) {
this.mActivityListCursorObj.close();
}
if (this.dbActListObj != null) {
this.dbActListObj .close();
}
} catch (Exception error) {
/** Error Handler Code **/
}// end try/catch (Exception error)
}// end onStop
It is of utmost importance that you close the Cursors, Databases, DBHelpers in the right order.
ReplyDeletefor e.g.
for the given code below.
DBHelper dbhelper = new DBHelper();
SQLiteDataBase db = dbhelper.getWritableDatabase();
Cursor c = db.query(/*some parameters*/);
the order of closing should be like:
c.close();
db.close();
dbhelper.close();
Otherwise different errors keeps on spawning and the developer does not even come to know about it.
If you are using a custom Class instance e.g. Model m that holds a DatabaseManager, which in turn holds a SQLiteDatabase: Model->DatabaseManager->SQLiteDatabase
ReplyDeleteThen, if you do a query to m (which does the appropiate delegations) and then you do something like m.close() (which actually closes the SQLiteDatabase) and after that you try to use the Cursor you will get that error.
The solution is: first use the cursor and then close the Db.
My response is based in the 2 existing so far, that inspired me to solve the problem.
Maybe this can help you: http://www.ragtag.info/2011/feb/1/database-pitfalls/
ReplyDeleteIt seems that calls to getReadableDatabase and getWritableDatabase returns the same connection to the database (even if you made several calls to them).
So, any call to close() on any of them will close both connection(s).
If you tries to use a cursor later, you'll get the nice 'Invalid statement', since the connection which the cursor relies on, is already closed.