简体   繁体   中英

Is it possible to stop a JNI call

I developed a c library. I call The c functions of the library from my JAVA code with JNI :

jstring Java_com_example_openafreerdp_UnboundedService_invokeNativeFunction(JNIEnv* env, jobject obj) {
    ...
}

The JNI function is called from java in this way:

public class UnboundedService extends Service {

    static {
        System.loadLibrary("hellondk");
    }
    private native String invokeNativeFunction();

    private class JniBackGround extends AsyncTask<String, String, String> {
        @Override
        protected String doInBackground(String... ss) {
            final String str = invokeNativeFunction();          
            return str;
        }
    }
    ...
    @Override
    public void onStart(Intent intent, int startId) {
        JniBackGround task = new JniBackGround();
        task.execute(new String[] { "http://www.any.com" });
    }
}

Now my C function take long time to fulfill execution. And I want to Add a button to stop this execution. How I can stop it with JAVA?

如果fx有某种inf循环,则while(true)他可以始终使用while(someFlag)并在此新的invokeNativeStopFunction内部将someFlag设置为false ...如果他使用的是curl库调用(我怀疑,因为url是(不传递给本机)他可以在那里取消卷曲请求……等等,等等……– Selvin

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM