Mar 22 | 7:20 PM |
Mark M. | has entered the room |
Mark M. | turned on guest access |
Mar 22 | 7:30 PM |
Andre R. | has entered the room |
Andre R. |
Hello Mark, nice to talk to you again.
|
Mar 22 | 7:35 PM |
Mark M. |
hello, Andre!
|
Mark M. |
how can I help you today?
|
Andre R. |
Ok. If you remember I am struggling to get Room going on my previous SQLiteHelper Database app.
|
Andre R. |
I got rid of Dagger and am making my database injection like this link
|
Andre R. | |
Andre R. |
I think this way I could have more control opening and closing the database to perform my backup copy and restoration
|
Mark M. |
OK, but I don't know what you are asking, so I don't know what to tell you
|
Andre R. |
I can manage to make the copy of my database to the sdcard with the database closed or opened. The problem is trying to open the database again if I close it.
|
Andre R. |
I have this error E/ROOM: Invalidation tracker is initialized twice :/.
|
Mar 22 | 7:40 PM |
Andre R. |
when I use (Room database instance) db.openHelper.writableDatabase to open it again
|
Mark M. |
it's possible that you are encountering a bug/limitation in Room
|
Andre R. |
and then my app crashes with the message Cannot perform this operation because the connection pool has been closed
|
Andre R. |
That is why I dont
|
Mark M. |
hmmm... I filed a somewhat related issue here: https://issuetracker.google.com/issues/65820362
|
Andre R. |
don't close it to copy the backup. Is there a problem to keep it opened while copying the file to the scared?
|
Andre R. |
sdcard sorry
|
Mark M. |
the risk is if other code -- such as the invalidation tracker -- tries doing database I/O while you are in the middle of copying
|
Mark M. |
the primary objective is to ensure that nothing can be manipulating the database in the middle of a copy
|
Andre R. |
Ok, so if I am sure that I am not making any kind of request to the database I am ok ?
|
Mark M. |
um, well, Room has its own stuff that accesses the database, such as the aforementioned invalidation tracker
|
Mark M. |
so, if the RoomDatabase is open, I am not certain how you can be sure that nothing else is working with the database while the copy is occurring
|
Mar 22 | 7:45 PM |
Andre R. |
So for now we are risking the data trying to do a backup with Room ?
|
Mark M. |
at least via the file-copy approach, yes, if we can't close and reopen the database, IMHO
|
Andre R. |
Well than an option is to close it, make the copy and kill the app.
|
Andre R. |
At least we have the backup.
|
Mark M. |
that doesn't sound user-friendly
|
Mark M. |
this is one of the reasons why I need to dig into this subject more
|
Mark M. |
and it's one of the reasons why I'm kicking myself for not having addressed this previously
|
Mark M. |
too many things to do, too little time...
|
Mark M. |
we need a clear solution for the backup problem
|
Ettie S. | has entered the room |
Mark M. |
and it sounds like the direction that I would be going is a direction that isn't working
|
Mark M. |
which means we need Googly advice, I suspect
|
Mark M. |
Andre: let me take a question from Ettie, and I'll return to you in a little bit
|
Mark M. |
Ettie: hi! welcome to the chat!
|
Mark M. |
if you have an Android app development question, fire away, and I can try to answer it
|
Mark M. |
Ettie: if you come up with a question, chime in, and I can turn to you
|
Mark M. |
but, in the meantime...
|
Mar 22 | 7:50 PM |
Mark M. |
Andre: back to you! do you have another question?
|
Andre R. |
Ok. I have managed to restore a backup by deleting the data in the active database, attaching the database file in scard and copying its content to the active database. It is taking more time than when I was able to close the database and just copy the file.
|
Andre R. |
I am using RxJava and tryied
|
Mark M. |
I am not surprised that attach-and-copy is slower than a straight copy
|
Mark M. |
straight file copy, that is
|
Andre R. |
tried this solution: http://tomstechnicalblog.blogspot.com.br/2016/0...
|
Mark M. |
that's unlikely to help here
|
Mark M. |
as you are single-threaded on the database access, at the SQLiteDatabase level
|
Andre R. |
Yes I have noticed, you already answered my question.
|
Ettie S. |
Hi. Sorry for the interruption. Can I ask about Services in Android 8?
|
Mark M. |
Ettie: sure, go right ahead!
|
Mar 22 | 7:55 PM |
Ettie S. | |
Ettie S. |
Thanks! I've been reading up on how to handle a Service in Android 8, which up till now, worked just fine. I've tried to use startForeground() but for some reason, I can't get the notification to show while the Service is running. I even converted my Service class into an IntentService just to see if it would work, but the same thing happened. Any ideas?
|
Andre R. |
Ok, so in your opinion, according to the actual moment of the Room database, I am in the right path of doing and restoring my backups ?
|
Mark M. |
Andre: yes, though, again, I'm nervous about keeping the database open
|
Mark M. |
Ettie: I am having a bit of difficulty following that code
|
Mark M. |
are you sure that shouldServiceRun() is returning true?
|
Mar 22 | 8:00 PM |
Mark M. |
beyond that, this code will only have your service be foreground during the "//all functions and calculations here" part
|
Mark M. |
so, depending on how quick that is, you might not see the actual foreground effect
|
Ettie S. |
True, but I see the notification from Android that an app is running in the background.
|
Ettie S. |
I'm not sure why that happens instead of the foreground notification.
|
Ettie S. |
shouldServiceRun() will return true.
|
Mark M. |
if you have not done so already, try fully uninstalling the app, then running it again
|
Mark M. |
particularly if you were trying other importance levels previously
|
Mark M. |
BTW, Andre, at this point, I'll try to take questions from both of you simultaneously, so chime in if you have a question
|
Andre R. |
It is funny this issue because we have this post
|
Andre R. | |
Andre R. |
and there she opens and closes the database in all method
|
Mar 22 | 8:05 PM |
Andre R. |
with the SupportSQLiteOpenHelper
|
Mark M. |
like I said, I need to spend more time on the database-closing issue
|
Mark M. |
but, particularly with a blog post with a handful of snippets, take the code with a grain of salt
|
Andre R. |
I mean because to get a SupportSQLiteOpenHelper you have to instantiate Room database
|
Mark M. |
agreed
|
Ettie S. |
After uninstalling and reinstalling, I see that the foreground notification shows and disappears quickly and then app is running in background notification appears.
|
Ettie S. |
Looks like something is working, but maybe not long enough?
|
Mark M. |
that implies that you are calling stopForeground(), but the service is still considered to be running
|
Mark M. |
is this the IntentService edition of your code?
|
Ettie S. |
Yes.
|
Mark M. |
OK, that's strange, as the service should be destroyed once onHandleIntent() returns
|
Andre R. |
Thank you for the support, despite of all I am a little bit happy that I was not totally wrong. See you.
|
Mark M. |
Andre: sorry I didn't have anything better for you!
|
Mar 22 | 8:10 PM |
Andre R. |
I will keep in touch to get any news. Thanks.
|
Mar 22 | 8:10 PM |
Andre R. | has left the room |
Mark M. |
Ettie: I'm not sure why the running-in-the-background notification is showing up if the service is destroyed
|
Ettie S. |
should I move the stopForeground() to the onDestroy()?
|
Mark M. |
that would be a worthwhile experiment
|
Mark M. |
for example, if your notification then sticks around, and you're sure that the background work is done, that implies that something is keeping your service around
|
Ettie S. |
I see.
|
Ettie S. |
Reviewing my onDestroy(), I already put stopForeground() and then stopSelf() in an if statement checking if it's Android O or not.
|
Mark M. |
you don't need stopSelf() in onDestroy(), as the service is already being destroyed
|
Mark M. |
you might consider adding some Log statements to see what of your code is getting executed when
|
Mar 22 | 8:15 PM |
Mark M. |
or, if you prefer, set breakpoints and run the app in the debugger
|
Ettie S. |
Ok. Thanks.
|
Ettie S. |
Thanks for your time and your insights.
|
Mark M. |
sorry that I didn't have a clear solution for you
|
Ettie S. |
I still appreciate it. Thanks.
|
Ettie S. | has left the room |
Mar 22 | 8:25 PM |
Mark M. | turned off guest access |