1

I have a big chunk of third-party native code that I'm running on Android using the NDK. This code contains global variables, and as such only supports a single session per process. (Unless Android has some magic way of loading multiple instances of a shared library into the same process.)

I have to be able to run multiple Activities concurrently. This means that each Activity has to run in a different process. Does anyone know any way I can do this?

Note that process affinity doesn't help here, is this allows me to specify a single named process that all instances of a single Activity class run inside. What I want here is to have multiple instances of an Activity class each running in their own process.

I'm on Gingerbread (or above); I'm willing to consider any foul hack to make this work...

(Also: at the risk of sounding tetchy, please do not explain to me why this is a bad idea and I should do something else. Telling me that my external requirements are wrong isn't helping me meet my external requirements...)

David Given
  • 13,277
  • 9
  • 76
  • 123
  • 3
    "This means that each Activity has to run in a different process" -- no, it means they should all be talking to a common component (e.g., a Service) that provides access to the library. "please do not explain to me why this is a bad idea and I should do something else" -- tough. Even if you can pull this off (which I sincerely doubt), you're going to consume a whole lot more memory, which your users will not appreciate. – CommonsWare Sep 05 '11 at 14:06

2 Answers2

1

How about this

android:multiprocess = true

check the docs. This should work.

catimos
  • 156
  • 1
  • 6
  • Thanks, but that's not quite the same thing! That allows my activity to run in the process of the activity which launches it. This means that if a third-party application launches my activity twice within the same process, I end up with two instances of my activity running within that process... which I can't allow. – David Given Apr 11 '13 at 21:56
1

You have to set both, android:taskAffinity and android:process in your manifest file for activities you wish launch in different processes.

Salw
  • 1,880
  • 17
  • 22
  • As I explained, that only allows me to specify a process for all instances of a given activity. I want to run each instance of the activity in a separate process. – David Given Sep 05 '11 at 15:04