0

In Android, is the main thread favored in the use of the CPU, compared to Service? If yes, can I give, for a certain period, the complete control of CPU to android service? Or more generally give different priority?

GVillani82
  • 17,196
  • 30
  • 105
  • 172

1 Answers1

1

If your question is related to the problems with db access, you should revisit your db access patterns, because that's where your problem lies. Otherwise, you may play with priorities and processor affinities and services and all this stuff, make the system unresponsive and eat the battery in an hour as a result, and still get the db access problems.

When there's a service with a need of constant RW access to the db, and you try to open the same db from another place, it would most definitely fail. Therefore, don't try to access db in onClick(), but have your service to prepare the necessary data and save it somewhere to be loaded when button is clicked without accessing the db.

Sorry, could not tell you more unless you explain the details of what kind of data you use and how you want to process it.

lenik
  • 23,228
  • 4
  • 34
  • 43
  • Thank you, but my button's name is "Reset Database", so I can't avoid this usage – GVillani82 Oct 30 '12 at 22:49
  • The problem is that when I stop the service, the sevice does not stop until the code of main thread is finished – GVillani82 Oct 30 '12 at 22:50
  • 1
    if your button is "reset db", then call your service and have it to do the reset for you. your service might check for these reset requests when not busy updating db. – lenik Oct 30 '12 at 23:06
  • The only problem is that my service is yet running when I call it for reset db. I can't access to shared variable for check reset request – GVillani82 Oct 30 '12 at 23:11