1

I have implemented a background service that read and writes different data from my app to my background server to a database.

On my first version I used two services for this. One created an entry in an queue, to know what task should be done next. The other service performed the task. A task was: Calling a PHP Script to read or write data with json.

So on a refactoring process, I did this differently. I had now one Service, which runs every 3 seconds and makes a thread which perfoms the task. The code for performing the data transfer did not change.

But now, the code runs soo slow and I also have memory leaks. So my question is: Is a service handled different as a thread in android? So does the service get more cpu or more memory?

Any ideas, why my second solution is slower?

Peter
  • 1,011
  • 2
  • 16
  • 39

1 Answers1

0

The matter is not of slowness of the app. worker threads are not managed by the Android system and you should terminate them when they are no longer needed. This means that a thread that is created in Activity.onStart() should be terminated in Activity.onStop(). Otherwise you will be creating new threads every time that the activity starts, resulting in leaking threads. This can be extremely devastating for performance. But in your case, nothing can be said, because I don't know what and how the operations are being performed. Sometimes logic used in the code may cause time consumption.

Abdul Waheed
  • 4,540
  • 6
  • 35
  • 58