0

Im wondering if there is a way in android to run tasks in the background by just using the android packages without using AsyncTask. What i imagine is a background task which is still running when the Activity is already finished or the app already got closed. I want the user to see the progress of this task in the notification tab of android (the tab you can swipe down from the top of the android screen).

I want to do this for example when i send e-mails or when i send data like images to the server. because they are quite long running tasks i dont want the user to wait for them to finish. i want them to run in the background so that the user can close the app. and i want the user to see the progress in the notification bar.

Also i would like to know if there is a way to automatically repeat such a background task when it failed because the device did not have connection to the internet.

Im looking forward to read the answers and to learn something new.

Mulgard
  • 9,877
  • 34
  • 129
  • 232

1 Answers1

0

You must use service. I think these links can help you to use it:

http://developer.android.com/training/run-background-service/index.html

http://inchoo.net/dev-talk/android-development/android-simple-service/

Download a file with Android, and showing the progress in a ProgressDialog

Example: Communication between Activity and Service using Messaging

Community
  • 1
  • 1
Arma
  • 152
  • 1
  • 12
  • What is the solution i need, the Service or the IntentService? – Mulgard Nov 29 '14 at 15:06
  • You need a service. it's a class in your project. – Arma Nov 29 '14 at 15:20
  • Its written in the documentation that a service can block my main thread. An IntentService is running in a worker thread. Why would a service be the best choice in your opinion? – Mulgard Nov 29 '14 at 15:44
  • 1
    oh i see. because the intentservice gets killed when the app gets shut down. thank you. – Mulgard Nov 29 '14 at 15:54