--
You received this message because you are subscribed to the Google Groups "android-ndk" group.
To unsubscribe from this group and stop receiving emails from it, send an email to android-ndk...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/android-ndk/22d6cebb-38c2-46aa-9ce0-1fd607a9effc%40googlegroups.com.
I'd suggest SWIG for doing the JNI (just because that's what it does and lots offolks have been using it for years.)
Once you have a class or interface for startReallyCoolVRStuffs, I'd put thatin a service and do the dance to make it a foreground service so Android doesn'tstep on it (in app user land that's as close as you can get to a daemon, if youare making your own firmware the rules are different.)
Your other choice is to just have one super-activity and do all your modal stuffinside that, but that's sort of ugly (but if you are porting some app that has a UIwritten in OpenGL or something, you could pull the whole thing over and justhave the android Activity give an area to draw until exit.)
If you are building a native component for custom Android-based device, it can be a native Linux-style service. You can start it in init.rc, and eve choose to run it as root or system.
If the device is not under your control, you can still create a child native process from an app (see Java ProcessBuilder). Such process will run with the uid of your app, and may get killed by the system if the resources are required to run some other foreground app.
Hello and thanks for your response!
Am Mittwoch, 7. August 2019 23:06:08 UTC+2 schrieb AppCoder:I'd suggest SWIG for doing the JNI (just because that's what it does and lots offolks have been using it for years.)Well, we already got a shared mem interface in place as we are porting this from different platforms, so I'd rather just use and extend this. As long as I can have C++ code run and be able to use shared memory I should be good to go.
Once you have a class or interface for startReallyCoolVRStuffs, I'd put thatin a service and do the dance to make it a foreground service so Android doesn'tstep on it (in app user land that's as close as you can get to a daemon, if youare making your own firmware the rules are different.)From this page I understand a foreground service doesn't have as many restrictions as to what it can do compared to a background service. In that regards, our would be service does mostly network IO. It fetches and synchronizes data of all sorts and provides a networking back-end to thr running VR application. While being quite efficient, it does require a bit of CPU and quite a bit of network. So if a background service would imply that I'd have restrictions in that area, it would be ruled out.
Well, the existing application is a Qt desktop app, fully native C++. We currently intend to strip the UI away and put the stuff that does the heavy lifting into this Android service. As it already has a shm interface we aim at having a native Android UI (presumably written in Java or being a game like C++ UI in VR). Either way, this shall only replace the UI and leave as much of the back-end libraries and functionalities intact as possible.
You can load the library via jni into an android service. my recomendation to communice with the ui component is via tcp/ip. I reco,mwnd it due to the volatility kf the android apis.. once you get it working, you don't want to keep changing it every time a new android veraion ships..... tcp/ip is stable
Let me take a few steps back and push some architecturestuff at you.
Apps are forked java processes with hooks to all the OS APIs.The official support for C++ is an attempt to emulate the hooksthat the java stuff uses (nativeActivity) or JNI linked into the javaprocess.
While it's tempting to say "oh, it's just a linux and clang, I knowC++, I can make this go", there are all sorts of little traps fornot doing things "the right way". Among those are:1) the SE Android set up (that some OEMs tighten downdifferently than others, nothing more annoying than havingyour developer phone run fine and find that 70% of yourSamsung users are sad because of how Samsung set uptheir Knox stuff.)2) bionic (the libc on android) has various short cuts, andrestrictions compared to what you might be used to (like,oh we don't fill out that struct, or that's not a supportedsyscall)
In the face of this, playing by the rules for a user appmeans more time doing your app, less time figuringout why this device/update borked your stuff.
In the face of all this, the most conservative/safe C++interaction as an app is JNI talking to java that livesfor the lifetime of an activity.
The slightly more "chase the APIs and keep it working"supported view is, make a foreground service in java,and call that JNI and meet the requirements to keepit alive. (In theory using the binder to an active UIcomponent and doing the notification etc for a foregroundservice provide similar benefits, assuming that youcan bind during activity transitions and not have agap where the Android takes down the service asnot in use.)
--
A question: are you delivering an app yourself, or are you just providing libraries for third-party use?