• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

synchronized methods in Android Activities

 
Ranch Hand
Posts: 98
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Ranch Hand
Posts: 231
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
reply
    Bookmark Topic Watch Topic
  • New Topic