Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Where exactly does NDK native code execute

I have some confusion about the life cycle of native code in Android aps. I have seen references that say that the native code is executed inside the Dalvik VM, but is that true? I was under the impression that the VM only runs Dalvik bytecode. On the otherhand, the native code uses JNI which is be called from Java inside the VM. Lastly, does the use of NativeActivity make any difference?

I thought I was understanding the NDK fairly well, until I sat down and tried to explain it to myself. I'm not even sure that I'm asking the question in a sensible manner.

like image 794
CatShoes Avatar asked Aug 16 '12 17:08

CatShoes


1 Answers

I have seen references that say that the native code is executed inside the Dalvik VM, but is that true?

It executes inside a process that contains a Dalvik VM. Personally, I would not describe it as executing inside the VM -- as you say, Dalvik bytecode executes inside the VM. "Under the control of the Dalvik VM" would be better phrasing, IMHO. Of course, it boils down to your definition of "in", I suppose.

Lastly, does the use of NativeActivity make any difference?

Not really, insofar as NativeActivity is implemented in Java. While you may not have any Java, Java is still lightly involved in the act of running your native code.

like image 155
CommonsWare Avatar answered Nov 15 '22 09:11

CommonsWare