Hi All,
Due to my Nexus 5X completely failing from a very common hardware issue, I now have a Pixel running Android 9 - which is my first device to do so.
Back when Erel announced that DoEvents was being deprecated & that Sleep should be used instead, I somewhat indiscriminately went through most of my apps & did exactly that. In hindsight, I probably should have been a bit more careful about it, but I've found that all those apps generally work fine - up until now.
During an update to myPets, testing showed that Android 9 seems to handle Sleep(0) differently to previous Android versions in some cases. There are many places in the code where I am discovering this, but one good example is the code below.
As I do a lot in this app, I show a progress dialog for functions that might take a little while to complete. You can see in the code below a commented out Sleep(0) below the call to ProgressDialogShow("Deleting..."). In the old days, I had a DoEvents there to give the UI a chance to display the dialog & in my pre-9 code I had the Sleep(0) uncommented & everything worked fine. However with Android 9 & the Sleep(0) uncommented, the records never get deleted - presumably because the Sleep causes the sub to return & never come back. I don't understand why.
I have a whole lot of other similar issues where using Sleep(0) causes unexpected results with Android 9, but no issues with earlier versions. Has anybody else seen this?
- Colin.
Due to my Nexus 5X completely failing from a very common hardware issue, I now have a Pixel running Android 9 - which is my first device to do so.
Back when Erel announced that DoEvents was being deprecated & that Sleep should be used instead, I somewhat indiscriminately went through most of my apps & did exactly that. In hindsight, I probably should have been a bit more careful about it, but I've found that all those apps generally work fine - up until now.
During an update to myPets, testing showed that Android 9 seems to handle Sleep(0) differently to previous Android versions in some cases. There are many places in the code where I am discovering this, but one good example is the code below.
As I do a lot in this app, I show a progress dialog for functions that might take a little while to complete. You can see in the code below a commented out Sleep(0) below the call to ProgressDialogShow("Deleting..."). In the old days, I had a DoEvents there to give the UI a chance to display the dialog & in my pre-9 code I had the Sleep(0) uncommented & everything worked fine. However with Android 9 & the Sleep(0) uncommented, the records never get deleted - presumably because the Sleep causes the sub to return & never come back. I don't understand why.
B4X:
Public Sub removePet(ID As Int)
Private mRec As Map
ProgressDialogShow("Deleting...")
'Sleep(0)
mRec.Initialize
mRec.Put("ID", ID)
Starter.sqlDB.BeginTransaction
Try
DBUtils.DeleteRecord(Starter.sqlDB, "tblPets", mRec)
mRec.Clear
mRec.Put("PetID", ID)
DBUtils.DeleteRecord(Starter.sqlDB, "tblHistoryHeader", mRec)
DBUtils.DeleteRecord(Starter.sqlDB, "tblAppointments", mRec)
DBUtils.DeleteRecord(Starter.sqlDB, "tblMedical", mRec)
DBUtils.DeleteRecord(Starter.sqlDB, "tblAlerts", mRec)
DBUtils.DeleteRecord(Starter.sqlDB, "tblWeight", mRec)
DBUtils.DeleteRecord(Starter.sqlDB, "tblAlbum", mRec)
DBUtils.DeleteRecord(Starter.sqlDB, "tblTraining", mRec)
DBUtils.DeleteRecord(Starter.sqlDB, "tblHiddenPets", mRec)
Starter.sqlDB.TransactionSuccessful
If File.Exists(File.DirInternal, ID & ".jpg") Then File.Delete(File.DirInternal, ID & ".jpg")
ProgressDialogHide
Catch
Starter.CL.CLog(LastException.Message)
Log(LastException)
ProgressDialogHide
End Try
Starter.sqlDB.EndTransaction
End Sub
I have a whole lot of other similar issues where using Sleep(0) causes unexpected results with Android 9, but no issues with earlier versions. Has anybody else seen this?
- Colin.