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 6538501
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T10:44:36+00:00 2026-05-25T10:44:36+00:00

I have a button in my app which leads to the UpdateActivity. This activity

  • 0

I have a button in my app which leads to the UpdateActivity. This activity doesn’t show anything just a progress bar and there is an AsyncTask running with the updates.

The AsyncTask takes quite a long time because I conect to a server and retrieve info from many tables and inserting them in the sqlite database and sending data from local database to the server.

I am wondring if it’s not better to use a service for this?? is it? On the other hand I have a doubt. When I press the back button I leave that activivty but the AsyncTask seems to be running in the back (because I have a toast to inform the user the job’s done and it shows much later (even if I have left that activity!).

Then I have another activity which requires data to be read and written to/from the db so if I am doing that while another thread (the downloading thread) is messing up with the database too, is it possible that something goes wrong? Is there a way to prevent that?
thanks in advance

  • 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-05-25T10:44:36+00:00Added an answer on May 25, 2026 at 10:44 am

    Running your task in a service is defiantly a good idea for any long running operation that
    will outlive your Activity.

    At the moment your thread continues to run after leaving the activity,
    but at any point that thread could be killed when the system kills the process.

    Also presenting the user with UI from an Activity that has been and gone is not good for the UX.

    The best thing to do is run your AsyncTask in a service and display status updates using a status bar notification. This way the user can get an update of the progress as and
    when they need to.
    A service with a status notification is seen as long running and the system won’t kill
    the process (and therefore your thread) unless you are really low on memory.

    As to the question of concurrent access to a database, you should probably write a ContentProvider to control access to your database. ContentProviders must be
    thread safe and will provide uniform access to your data within any part of your app
    and can even be used by other apps should you wish to export your data.

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

Sidebar

Related Questions

in my android app, I have a button that leads to an activity which
I have a .NET application that contains a checkbox (System.Windows.Forms.Checkbox). This component (WindowsForms10.BUTTON.app.0.378734a1) is
I'm now testing GKPeerPickerController. I have a simple app that just have a button
I have an app in which the user clicks a button, triggering an iFrame
in my activity I have login page (L), which leads to hierarchy of activites
I am a beginner at this :) I have an app which changes an
I have an view in my App which has a number of buttons based
I have a button that launches the google maps app on my device via
Hello StackOverflow'ers, I have a (flex) app that, on the click of a button,
In my app there is requirement that..I have 6 buttons in a nib, when

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.