0

In Android, it allow each app using about 16Mb ram. I want to ask that i start a new service running in background. Can i use another 16Mb ram in this service??

Thanks.

King Wu
  • 387
  • 1
  • 8
  • 22

2 Answers2

0

If you use 16MB in the service alone, you are likely to have an OutOfMemory exception. Because the activities need some ram too. The heap size is what the application is allowed to use. You can not go beyond that. And any service will be part of that application even running in the background.

Lazy Ninja
  • 22,342
  • 9
  • 83
  • 103
  • You can use this to get the heap size of the device.
    long heap = Runtime.getRuntime().maxMemory(); int mega = 1024 * 1024; Log.d("TAG", "Heap size is " + heap/mega + " MB" );
    – Lazy Ninja Aug 10 '12 at 00:45
0

In Android, it allow each app using about 16Mb ram

The amount of heap space available to a process varies by Android version and device configuration. Most devices in use today have more than 16MB available to them.

I want to ask that i start a new service running in background. Can i use another 16Mb ram in this service?

By default, that service will be in the same process as the rest of the components in your app and therefore will share the same heap.

CommonsWare
  • 986,068
  • 189
  • 2,389
  • 2,491