Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6566021
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T14:10:02+00:00 2026-05-25T14:10:02+00:00

My app is partly written in native app using C/C++. The problem is that

  • 0

My app is partly written in native app using C/C++. The problem is that whenever C/C++ part crashes for some reason the app dies and then restarts automatically. This causes all kinds of messy problems

Now of course, it should not crash in the native part and I’m trying to weed out all reasons why it would happen. However, if it does happen I’d like to:

  1. Quit gracefully
  2. If it does die, at least not try to restart automatically.

I’m curious as to why this behaviour happens. After some search I tried putting the following line in the main activity element of the AndroidManifest.xml:

android:finishOnTaskLaunch="true"

but the automatic restore still happens.

Anyone knows why this is happening and how to change it?

UPDATE:
I think a more fundamental question is,
Is there something similar to a callback if there is a native crash?

One of the answers suggested ‘handling crash signals’. I’d be grateful for any links on how it can be done at an application or module level.

As it stands currently, if there is a crash the app just disappears, there’s nothing in logcat, so no debugging is possible.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-25T14:10:03+00:00Added an answer on May 25, 2026 at 2:10 pm

    Try to handle crash signals (SIGSEGV etc.) and send kill to yourself in signal handler. This trick helps me.

    Example:

    #include <signal.h>
    #include <unistd.h>
    
    
    static void signal_handler(int signal, siginfo_t *info, void *reserved)
    {
      kill(getpid(),SIGKILL);
    }
    
    extern "C" jint JNI_OnLoad(JavaVM* vm, void* /*reserved*/)
    {
      struct sigaction handler;
      memset(&handler, 0, sizeof(handler));
      handler.sa_sigaction = signal_handler;
      handler.sa_flags = SA_SIGINFO;
      sigaction(SIGILL, &handler, NULL);
      sigaction(SIGABRT, &handler, NULL);
      sigaction(SIGBUS, &handler, NULL);
      sigaction(SIGFPE, &handler, NULL);
      sigaction(SIGSEGV, &handler, NULL);
      sigaction(SIGSTKFLT, &handler, NULL);
      return(JNI_VERSION_1_6);
    }
    

    UPDATE2

    if you want to see crashlog in android logcat you should use this signal handler

    static void signal_handler(int signal, siginfo_t *info, void *reserved)
    {
     struct sockaddr_un addr;
     size_t namelen;
     socklen_t alen;
     int s, err;
     char name[] = "android:debuggerd";
     namelen  = strlen(name);
    
     // Test with length +1 for the *initial* '\0'.
     if ((namelen + 1) > sizeof(addr.sun_path)) {
        errno = EINVAL;
        return;
     }
    
     /* This is used for abstract socket namespace, we need
      * an initial '\0' at the start of the Unix socket path.
      *
      * Note: The path in this case is *not* supposed to be
      * '\0'-terminated. ("man 7 unix" for the gory details.)
      */
     memset (&addr, 0, sizeof addr);
     addr.sun_family = AF_LOCAL;
     addr.sun_path[0] = 0;
     memcpy(addr.sun_path + 1, name, namelen);
    
     alen = namelen + offsetof(struct sockaddr_un, sun_path) + 1;
    
     s = socket(AF_LOCAL, SOCK_STREAM, 0);
     if(s < 0) return;
    
     RETRY_ON_EINTR(err,connect(s, (struct sockaddr *) &addr, alen));
     if (err < 0) {
        close(s);
        s = -1;
     }
    
     pid_t tid = gettid();
     if(s>=0)
     {
       /* debugger knows our pid from the credentials on the
        * local socket but we need to tell it our tid.  It
        * is paranoid and will verify that we are giving a tid
        * that's actually in our process
        */
        int  ret;
    
        RETRY_ON_EINTR(ret, write(s, &tid, sizeof(unsigned)));
        if (ret == sizeof(unsigned)) {
            /* if the write failed, there is no point to read on
             * the file descriptor. */
            RETRY_ON_EINTR(ret, read(s, &tid, 1));
            //notify_gdb_of_libraries();
        }
        close(s);
     }
    
     wait(NULL);
     kill(getpid(),SIGKILL);
    }
    

    I took it from android source (can’t insert link because android.git.kernel.org is down), but I am not sure that it will work in future Android releases

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I've written an Android app that needs the short timezone name in which the
I have a Windows desktop app written in C# that loops through a bunch
I have a third-party app that creates HTML-based reports that I need to display.
We extensively use a third party app that we'll call thirdparty.com. thirdparty.com and mysite.com
I'm working on an interface with a 3rd party app that basically needs to
I'm trying to parse some data returned by a 3rd party app (a TSV
In one app, I have a task to create files that will be used
I am using Zend Framework and 3rd party application written in php for file
I have a Java app that needs to integrate with a 3rd party library.
I'm building a Zend-based Web app that will permit third-party extensions. Essentially, this application's

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.