Obtaining android_app*

964 views
Skip to first unread message

Dan

unread,
Dec 3, 2011, 7:49:32 AM12/3/11
to android-ndk
Hello,
I have a shim JAVA main activity so that I can use the layout
classes, etc.
for the UI. However, I also have a bunch of NDK code that needs
various
pointers to access hardware, loopers, etc.
Is it possible to obtain an android_app pointer in NDK code,
even though there is no android_main() entry? This information
would be very useful to have, even though I am not running
a native activity.
For example, how is it that ASensorManager_getInstance()
is able to access information about the application? Presumably,
this function is using a call to getSystemService() with information
about the application and context. Where is this stored, so that
I could construct something that would be equivalent to the
ASensorManager_getInstance() function in my native code. Thanks!
-Dan

David Turner

unread,
Dec 3, 2011, 3:35:51 PM12/3/11
to andro...@googlegroups.com
On Sat, Dec 3, 2011 at 1:49 PM, Dan <ddlee...@gmail.com> wrote:
Hello,
 I have a shim JAVA main activity so that I can use the layout
classes, etc.
for the UI.  However, I also have a bunch of NDK code that needs
various
pointers to access hardware, loopers, etc.
 Is it possible to obtain an android_app pointer in NDK code,
even though there is no android_main() entry?  This information
would be very useful to have, even though I am not running
a native activity.

No, this is not possible, the fact that you have an android_app pointer comes from special support code in the system which is used to implement the NativeActivity class. In other words, if your activity class is not derived from NativeActivity, it can't get valid pointers like these.
 
 For example, how is it that ASensorManager_getInstance()
is able to access information about the application?  Presumably,
this function is using a call to getSystemService() with information
about the application and context.  Where is this stored, so that
I could construct something that would be equivalent to the
ASensorManager_getInstance() function in my native code.  Thanks!

Same thing here. You need to be a subclass of NativeActivity.

 
-Dan

--
You received this message because you are subscribed to the Google Groups "android-ndk" group.
To post to this group, send email to andro...@googlegroups.com.
To unsubscribe from this group, send email to android-ndk...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/android-ndk?hl=en.


Dan

unread,
Dec 3, 2011, 8:29:13 PM12/3/11
to android-ndk
So, it's not possible to write something equivalent to the
ASensorManager_getInstance() using the NDK?
Somehow, that function is accessing information about the activity
context,
even though it hasn't explicitly been passed some sort of pointer.
Presumably, it's doing some sort of call to
getSystemService(SENSOR_SERVICE)
on the activity object stored internally somewhere.

For example, in my application, it would be nice to be able to write
something
like AVibrator_getInstance(), without explicitly passing down the
activity pointer
through some JNI call from the Java activity object.
-Dan

Reply all
Reply to author
Forward
0 new messages