1

Question: Is it possible to share natively allocated data across multiple threads on Android?

Example: In the onCreate() function, I allocate a struct on the heap using native code and return a pointer to that data. Later on in the application, I would like to use that data in a different thread, in my case a GLThread used to render the data out...

Is this possible? If so, what would be the best way to go about this?

Erik
  • 804
  • 1
  • 8
  • 18
  • I'm going to answer my own question : I found the solution [here][1] [1]: http://stackoverflow.com/questions/5802340/passing-a-pointer-from-jni-to-java-using-a-long – Erik Jan 10 '12 at 08:19

1 Answers1

0

I dont know if I understand the problem, you want to have some kinda share data object? In my case I use something like this:

Create new class, which extends from application and there you can keep the variable with public getter and setter.

In any of your intent you can just call for this class:

DataHolder data = (DataHolder) getApplication();

Don't foget to add this class to manifet as application.

goodm
  • 7,275
  • 6
  • 31
  • 55
  • Hello goodm, thank you for your answer. You are correct, I'm looking for some sort of shared data object. The complexity comes from the fact that the data is allocated by native (c++) code and that I would like that data to be accessed by multiple threads. – Erik Jan 06 '12 at 09:47
  • I have never worked before with c++ on android, in this case I dont know how to help you, maybe some database? – goodm Jan 06 '12 at 09:49