Creating a background application using NDK ( C code only )

278 views
Skip to first unread message

Raj

unread,
Aug 8, 2018, 12:55:21 PM8/8/18
to android-ndk
    New to Android development & to NDK, Need help in creating background helper application's using NDK. I have to port a large application in C to Android platform and my main C application makes use of few standalone applications which run in the background (as services on windows & as daemons on Linux). So how can I create these standalone applications in Andriod platform. I'm aware that these have to be services in Android applications, but the services are written using Java code & NDK doesn't support services & all my application code is in C. So how can I port these standalone applications onto Android along with my main application which uses these standalone helper applications. Should they be made separate libraries ? I'm not sure, so any pointers will be very helpful. Please Note: Rooting the device is not allowed.

Damien Cooke

unread,
Aug 8, 2018, 8:26:46 PM8/8/18
to android-ndk
You will need to write entry functions in C using JNI to allow them to be called from Java.  Even the services you need to run should be ok (I have never written a service containing JNI ) as you should just call your entry functions from:

@Override
public int onStartCommand(Intent intent, int flags, int startId) 
{
.......
}

I would start with one of the services and essentially write a C routine that starts the daemon using JNI exports.  Then import that and execute it in the above Service callback method.  Make sure you clean up by creating a JNI C method to clean up the C library and call it in 

@Override
public void onTaskRemoved(Intent rootIntent)
{
.........
}


it is a big job you have been handed, I can give you some sample methods etc if you get back to me to help you get going.

Damien


On Thu, Aug 9, 2018 at 2:25 AM Raj <rajash...@gmail.com> wrote:
    New to Android development & to NDK, Need help in creating background helper application's using NDK. I have to port a large application in C to Android platform and my main C application makes use of few standalone applications which run in the background (as services on windows & as daemons on Linux). So how can I create these standalone applications in Andriod platform. I'm aware that these have to be services in Android applications, but the services are written using Java code & NDK doesn't support services & all my application code is in C. So how can I port these standalone applications onto Android along with my main application which uses these standalone helper applications. Should they be made separate libraries ? I'm not sure, so any pointers will be very helpful. Please Note: Rooting the device is not allowed.

--
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 post to this group, send email to andro...@googlegroups.com.
Visit this group at https://groups.google.com/group/android-ndk.
To view this discussion on the web visit https://groups.google.com/d/msgid/android-ndk/87314142-45f0-48b4-8ad2-ce9e28502c50%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Raj Shekar

unread,
Aug 9, 2018, 3:57:52 PM8/9/18
to andro...@googlegroups.com
Hi Damien,

    Thanks for your time & reply, your help would definitely help me in getting the project up & running. Currently, I have the NDK set up and have a sample application which uses JNI and native code. I have the main activity which uses JNI. The methods onStartCommand( ... ) & onTaskRemoved( ... ) are used to create the services & when the service is stopped respectively, should I be creating the services in the main activity or where ? May be I'm asking too basic questions, but I want to be sure that it's the right way to do it.

Can you please help me in understanding - 'write a C routine that starts the daemon using JNI exports. Then import that and execute it in the above Service callback method.  Make sure you clean up by creating a JNI C method to clean up the C library and call it in onTaskRemoved( ... ) method '. (sorry that I didn't get exactly the meaning).

And finally, it would be very helpful if I can get some example on either Github or in some other repository. It would be really helpful.

Thanks for your time again.

Thanks,
Raj.

Reply all
Reply to author
Forward
0 new messages