简体   繁体   English

在Activity中调用Runnable类

[英]Call a Runnable class inside an Activity

I've a Runnable class , Is it possible to call this runnable class inside an activity ? 我有一个Runnable类,是否可以在一个活动中调用这个runnable类?

Here is my class : 这是我的班级:

public class TstClass implements Runnable {

static boolean m_bret = false; 
static String m_szconfig = "-i";
private int n_stat;
public native String unimplementedStringFromJNI();


static {
    try {
        System.out.println ( "[AdDBCache] Module load try ffmpeg : " + System.getProperty("java.library.path"));
        System.loadLibrary("tstjni");
        System.out.println ( "[AdDBCache] Module load success");

     } catch ( Exception e ) {
         System.out.println ( "[AdDBCache] Module load err : " + System.getProperty("java.library.path"));
}
}

private static synchronized final native int mod_run (String name, String sztoken );

public void set_config ( String sz_config ) {
    m_szconfig = sz_config;
}


public void run_core ( String sz_file, String sz_token ) {
    m_bret = false;
    n_stat = mod_run ( m_szconfig, sz_token );
    m_bret = true;
}


public void run () {
    run_core ("", "");
}

}

Logcat error: Logcat错误:

03-14 17:53:11.405: E/AndroidRuntime(2605): FATAL EXCEPTION: Thread-8
03-14 17:53:11.405: E/AndroidRuntime(2605): java.lang.UnsatisfiedLinkError: mod_run
03-14 17:53:11.405: E/AndroidRuntime(2605):     at com.parsapp.actionmovie.ffmpeg.mod_run(Native Method)
03-14 17:53:11.405: E/AndroidRuntime(2605):     at com.parsapp.actionmovie.ffmpeg.run_core(ffmpeg.java:31)
03-14 17:53:11.405: E/AndroidRuntime(2605):     at com.parsapp.actionmovie.ffmpeg.run(ffmpeg.java:37)
03-14 17:53:11.405: E/AndroidRuntime(2605):     at java.lang.Thread.run(Thread.java:1096)

Have you tried the following? 你试过以下吗? Did you encounter any problems? 你遇到过什么问题吗?

TstClass tst = new TstClass();
new Thread(tst).start();

Documentation: http://docs.oracle.com/javase/1.4.2/docs/api/java/lang/Thread.html 文档: http//docs.oracle.com/javase/1.4.2/docs/api/java/lang/Thread.html

new TstClass().run(); 

should be work . 应该工作。 Have you tried? 你有没有尝试过?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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