Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

synchronized methods in Android Activities

 
Matt Pavlovich
Ranch Hand
Posts: 98
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have two activities. In activity 1 I write a value to a SQLite database by entering that value into an EditText field. Once I press the submit button, the data is written and I am moved along to another activity - activity 2. Activity2 also does the same thing in that I can write new data and persist it to the database with a button click. So, my question is: do I need to synchronize the method (which is on a separate thread from the UI) in activity 1, as well as the method in activity 2 in order to prevent thread safety issues in the database? Keep in mind that both methods access the same database but from different activities. Technically, activity 1 should be complete with onStop having been called and the new activity (activity 2), now being visible. Is it even possible for these two activities and their corresponding threads accessing the database (via different methods) to have any kind of concurrency problems given the Android activity life cycle?

Thanks very much, Matt
 
Harvinder Thakur
Ranch Hand
Posts: 231
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

I hope i've understood your question correctly!!

Since both the activities 1 & 2 would be accessed by a button click from the respective UI of the activity, it seems impossible to have a concurrent database access issue in case of these two activities. A user cannot click two buttons in two different UIs at the same time.

Does this answer your query?
 
Matt Pavlovich
Ranch Hand
Posts: 98
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This was my thinking as well. My only concern was the slim possibility of the database hanging for some reason, since the thread could technically continue to run from activity 1 even after that activity has stopped. However, the chances of that happening are, I think, pretty remote. I just wanted to get a second opinion.

Thanks for your input.
Matt
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic