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 5954469
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T17:58:31+00:00 2026-05-22T17:58:31+00:00

{Apologies for the cross-post with android-developers forum. Haven’t received any answers there} I have

  • 0

{Apologies for the cross-post with android-developers forum. Haven’t received any answers there}

I have an interesting design challenge:

I have a frontend(Activity) and a backend (written in native C/C++)
code. The backend is a complex object which partially controls the
flow of application & once started runs in it’s own thread. So I have
a “distributed control” scenario.

The Activity needs to be able to send messages asynchronously to the
backend which then takes certain actions. But the backend also needs
to be able to send messages asynchronously
to the Activity, to which
it responds by chnaging UI, firing methods etc.

Essentially what I need is a two-way listener.

So backend sends a message to screen (take picture, prompt user, get
location, take another picture now etc) and screen does what it needs
to do. But in addition, the screen should also be able to call the
backend-listener to send back messages (captured camera image, system
generated – “I got paused/destroyed” message, etc) in the callbacks of
these events. Main problem is that this is all asynchronous.

Is this possible without tight-coupling? Is this even possible?

I have thought of Asynctask/handlers (but that’s a one way street for
informing the UI thread), observer-pattern (both objects will be
observer/observable?) but confused on where to begin. Any thoughts,
links would be very helpful.

  • 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-22T17:58:31+00:00Added an answer on May 22, 2026 at 5:58 pm

    Within your native code, you can use JNI to obtain classes (and objects) from your VM, and once you’ve got a class (or object) you can locate methods and call them (static methods for a class, all methods for an object). It seems to me that the simple solution is to provide a helper in your java class which encapsulates the native methods and have the native code call into it.

    In the past, I’ve needed to have native code determine if its thread has been interrupted at the Java level. Java provides java.lang.Thread.currentThread() as a static to find your own thread, and java.lang.Thread.isInterrupted() to [non-destructively] determine the interrupted status. I used the following to solve this problem at the native level; perhaps you can use it towards your needs (with appropriate adaptation to message sending, of course):

    /* JavaThread: this class is a simple wrapper to be used around    */
    /* JNI's Thread class. It locates the provided functions as needed */
    /* and when it is destroyed (such as going out of scope) it will   */
    /* release its local references.                                   */
    class JavaThread
    {
    public:
        JavaThread(JNIEnv *env)
        {
            mEnv = env;
    
            /* find the Java Thread class within the JVM: */
            mThread = mEnv->FindClass("java/lang/Thread");
    
            /* find the Thread.currentThread() method within the JVM: */
            mCurrentThreadMID = mEnv->GetStaticMethodID(mThread, "currentThread", "()Ljava/lang/Thread;");
    
            /* find the current thread's isInterrupted() method: */
            mIsInterruptedMID = mEnv->GetMethodID(mThread, "isInterrupted", "()Z");
        }
        ~JavaThread()
        {
            if (mThread)
            {
                mEnv->DeleteLocalRef(mThread);
                mThread = 0;
            }
        }
    
        bool isInterrupted() {
            bool bResult;
            if (!mThread)           return false;
            if (!mIsInterruptedMID) return false;
    
            /* find the current thread (from the JVM's perspective): */
            jobject jCurrentThread = (jobject)mEnv->CallStaticObjectMethod(mThread, mCurrentThreadMID);
            if (NULL == jCurrentThread) return false;
    
            /* see if the current thread is interrupted */
            bResult = (bool)mEnv->CallBooleanMethod(jCurrentThread, mIsInterruptedMID);
    
            /* delete the current thread reference */
            mEnv->DeleteLocalRef(jCurrentThread);
    
            /* and return the result */
            return bResult;
        }
    
    private:
        JNIEnv    *mEnv;
        jclass     mThread;
        jmethodID  mCurrentThreadMID;
        jmethodID  mIsInterruptedMID;
    };
    

    Instantiation is based on the JNIEnv * provided to your native method, and a simple allocate/call/deallocate line of code to call the isInterrupted() method is:

    if (JavaThread(env).isInterrupted()) { ... }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

First and foremost, apologies for any cross-posting. Hope I'm not repeating an issue here,
Apologies for cross posting (I asked this on the Silverlight Forum but got no
Apologies for the poor question title. I have two tables, jobs and Persons-Jobs. Jobs
Apologies for a simple question, but I'm very new to Perl! I have an
Apologies if this has been answered previously. Say I have the following table: colA
Apologies but my knowledge of url rewriting is limited! I have setup urls to
Apologies if this conflicts with a previous post of mine, but I am pretty
First off, I apologize if it's considered poor etiquette to cross-post on stackexchange sites,
Apologies in advance for the long-winded question. I'm really a database programmer, but have
Apologies if this has been asked already. I've seen answers regarding static SQLs, but

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.