If setting the thread priority does not work, then I can only think of:
- break the job into small chunks and schedule an alarm for each chunk
- and possibly schedule the jobs for what you hope the phone's owner
is asleep
- put lots of sleep(s) in your code - every other line do sleep(1).
- all of the above.
On Thursday, May 24, 2012 8:45:07 PM UTC+1, Matt Quigley wrote:
>
> There's something in the app that happens in the background
> sporadically (daily to weekly). It's CPU intensive, but I don't want
> it to slow down the device. Right now, I'm creating a thread with
> MIN_PRIORITY, but it doesn't seem to help in anyway from the perceived
> "slowdown" of the phone while the thread is running.
>
> Thread thread = new Thread() {
> @Override
> public void run() {
> // cpu-intensive stuff here...
> }
> };
> thread.setPriority(Thread.MIN_PRIORITY);
> thread.start();
>
> Some ideas I'm thinking about:
> - Creating a service specifically for this thread, instead of using
> the existing component (Activity/Service/etc.) it was initiated from.
> - Object.wait()ing occasionally (although that really won't stop any
> CPU intensive stuff from occurring)
> - Putting the thread in its own service in its own process, then
> giving the process minimum priority. Thing is, I don't know how to
> make a process use less CPU time.
>
> Any tips or links on how to get a thread to use less CPU*? More
> broadly, to prevent some thread from slowing Android down?
>
> Thanks,
> -Matt
>
> * Technically it's not using less CPU - I still have to do the same
> things. Really, it's spreading the CPU use out over more time, so
> technically it's less CPU usage per unit of time.
--
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en