Once your app is in the background, you no longer have control of your resources. There are a few things that can be done to have some resources, but if your app attempts to hog or deliberately consume resources, you will be terminated.
While your app is in the foreground, you can use as much memory and CPU time as you want, but at your own hazard. If you stall the UI thread too long, you will be killed. If the system believes your background thread is hung at 100% CPU usage, you will also be killed.
Why are you trying to do this? If we knew your goals, we may be able to offer better ways to achieve them. What you are suggesting now is a dead end.