'Exiting the Android Foreground Service process from native layer

The problem:

I have a Foreground Android Service starter as STICKY that runs almost completely in the native layer (Service onStartCommand starts a Java Thread that then calls a blocking myStart method from a native library). I need to be able to restart the process completely from the native layer (complete exit so that the native library is loaded once again), without the Android System seeing it as a crashed service, considering that for every crash of the STICKY service that happens in a shorter time interval, the Android System increases a delay for the next restart.

The current "solution":

I am using an exit(0) call right before the return statement of the native myStart function. This is still detected as a crash by the system though.



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source