Discussion:
Creating a background application using NDK ( C code only )
(too old to reply)
Raj
2018-08-08 09:41:12 UTC
Permalink
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 android-***@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.
Damien Cooke
2018-08-09 00:15:57 UTC
Permalink
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
Post by Raj
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
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
<https://groups.google.com/d/msgid/android-ndk/87314142-45f0-48b4-8ad2-ce9e28502c50%40googlegroups.com?utm_medium=email&utm_source=footer>
.
For more options, visit https://groups.google.com/d/optout.
--
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 android-***@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/CAFE05Bbp7suT%2B8PPAKtUDGSr8zTd09BCJTBD6HJYB18AU%2B4vQQ%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.
Raj Shekar
2018-08-09 09:07:01 UTC
Permalink
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.
Post by Damien Cooke
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
@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
Post by Raj
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
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
<https://groups.google.com/d/msgid/android-ndk/87314142-45f0-48b4-8ad2-ce9e28502c50%40googlegroups.com?utm_medium=email&utm_source=footer>
.
For more options, visit https://groups.google.com/d/optout.
--
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
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/CAFE05Bbp7suT%2B8PPAKtUDGSr8zTd09BCJTBD6HJYB18AU%2B4vQQ%40mail.gmail.com
<https://groups.google.com/d/msgid/android-ndk/CAFE05Bbp7suT%2B8PPAKtUDGSr8zTd09BCJTBD6HJYB18AU%2B4vQQ%40mail.gmail.com?utm_medium=email&utm_source=footer>
.
For more options, visit https://groups.google.com/d/optout.
--
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 android-***@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/CAOpHf7OK5_5exgB97KBd1thBWSjVrtAc3S%3DmLKJQDBpbmNs0wQ%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.
Loading...