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

  • SEARCH
  • Home
  • 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 8468565
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T15:58:14+00:00 2026-06-10T15:58:14+00:00

I have an app that needs to do an intensive database operation on start

  • 0

I have an app that needs to do an intensive database operation on start up. The app holds a local copy of the contacts on the phone and synchronizes with the android contact database on startup.

If a user starts the app, an Async Task is started that does the database synch in the background. If the user closes the app, the operation continues running which is fine. However if the user opens the app again, the Async Task is started and an error is produced.

Is there anyway of checking if the Task is already running from a different instance of the app?

  • 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-10T15:58:16+00:00Added an answer on June 10, 2026 at 3:58 pm

    I think you should check the concept of Application in Android.
    http://developer.android.com/reference/android/app/Application.html

    In fact there is no such thing as

    different instance of the app

    . The Application is always the same for all your Activities/Services.
    That means that you’d left the Activity and opened it again, 2 cases are possible:

    1. The system already killed your application. In this case AsyncTask is dead already and it’s safe to start a new one
    2. The Application was still alive, so AsyncTask possibly still running.

    In 2nd case I will recommend to use some static variables, pointing to this AsyncTask or it’s state. If your app was still alive when 2nd time opened – all static references will be still valid, so you can successfully operate.

    PS: By the way, in current approach be aware that your application can be terminated by the system at any time. So AsyncTask can be interrupted in any moment. It it’s not ok for you – please check IntentServices – components, specially designed for background-operation purpose. http://developer.android.com/reference/android/app/IntentService.html

    Good luck!

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a Rails app that needs to expose values from a database as
I have an app that needs to check a database table every minute. The
I have an app that needs to read a PDF file from the file
We have an app that needs to access network resources. It's written in VB.Net.
I have an app that needs to be able use either an sqlite3 datebase
I have an app that needs backgrounds for both parts of the split view.
I have a wpf app that needs to communicate(exchange data) with a custom designed
I have an app that has a bunch of Core Data that it needs
I have a MySQL/Rails app that needs search. Here's some info about the data:
I have an app included into INSTALLED_APPS that needs to be monkey-patched. The problem

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.