Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8858249
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T14:47:07+00:00 2026-06-14T14:47:07+00:00

I’m trying to do a custom calendar in my app with event sync with

  • 0

I’m trying to do a custom calendar in my app with event sync with a WebService.

Everything goes just fine (well, not really).

The Calendar Activity starts an AsyncTask in order to get current month events and store them in the database and the onPostExecute method updates the view to properly mark each day.

My problem comes when the user gets to the calendar activity and then quickly goes back to main activity several times, let’s say for instance

Main Activity > Calendar Activity (Press Back button) > Main Activity > Calendar Activity (Press Back button) > …

At this point Activity freezes due to a database lock has not been available for 30 sec. or App crashes due a SQLiteConstraintException: error code 19

EDIT: SQLiteConstraintException behaviour no longer happens

Because being updated is very important in my app, every time I re-enter the Calendar Activity I delete the database and re-populate it with server new data even tough it is the same, and at this point is where the lock is made.

EDIT:

I’ve changed Delete > Insert style to:
Update all data (set flag column = 0) > Insert new data (set flag column = 1) > Delete (where flag column = 0)

I have already tried this solution to cancel the AsyncTask on Activity finish with no success

I am sure the problem is I don’t completely understand the process of what I am doing so I am missing something really important (or basic).

Any help improving my code or just pointing me to the right direction, would be much appreciated.

Thanks in advance!

EDIT:

My application has an Aplication which is in charge of creating a single Database connection (getWriteableDatabase();) and this unique conection is reachable trough MyApp.getDatabase(); method.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-14T14:47:09+00:00Added an answer on June 14, 2026 at 2:47 pm

    Main Activity > Calendar Activity (Press Back button) > Main Activity > Calendar Activity (Press Back button) > …

    That will likely create & start a new AsyncTask each time you you open the calendar.

    Each AsyncTask will still run if you don’t cancel it expicitly.

    And it depends on the Android version / executor you use to execute the AsyncTask if they run in parallel or serialized. The default behavior for >= Honeycomb would be serial execution. Explained in the Order of execution section in AsyncTask documentation.

    If you use serial AsyncTask you can have several of your (old) tasks queued up and it can take quite some time before your most recent task is executed. It might be a good idea to cancel tasks when you leave an Activity.

    The database lock has not been available for 30 sec. warning you get indicates that you write in one thread and try to access the database from another thread at the same time. Not sure if that requires two write threads in parallel.

    The problem is not using different SQLiteDatabase instances. I think you would get errors instead of that warning if you were doing that since Android can’t check if some random SQLiteDatabase object has a write lock on the database.

    So what can you do:
    I assume you use transactions since locking the database for long without transaction is pretty much impossible.

    • limit the size of your transactions to a certain amount so there is guaranteed break in between to use the database from other threads.
    • dynamically stop the transaction using db.yieldIfContendedSafely(). That will check if another thread wants to access the database and temporarily ends the transaction. Drawback: It will commit the change and you can’t rollback the whole transaction.
    • experiment with SQLiteDatabase#enableWriteAheadLogging() & beginTransactionNonExclusive() as mentioned in the write-ahead-logging documentation. It reads like it could allow multithreaded access without locking problems. I have not investigated further if that works and what side-effects it has.
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to convert HTML to plain text. I get many &\#8217; &\#8220; etc.
I am trying to understand how to use SyndicationItem to display feed which is
Basically, what I'm trying to create is a page of div tags, each has
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have just tried to save a simple *.rtf file with some websites and
I am trying to render a haml file in a javascript response like so:
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
We're building an app, our first using Rails 3, and we're having to build
I'm trying to select an H1 element which is the second-child in its group

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.