我将LibModule.java设置为Reactnative中的本机模块
.....
class LibModule extends ReactContextBaseJavaModule {
boolean readingMyKad = false;
....
public void read_mykad_main() {
clear_results();
pre_card_status = -1;
new readMyKad(reactContext).execute();
}
public static class readMyKad extends AsyncTask<Void, Void, Integer> {
CountDownTimer readMyKadCdt;
readMyKad readMyKadObject;
private WeakReference<ReactApplicationContext> activityReference;
readMyKad(ReactApplicationContext reactContext) {
activityReference = new WeakReference<>(reactContext);
}
protected void onPreExecute() {
readMyKadObject = this;
readMyKadCdt = new CountDownTimer(25000, 1000) {
@Override
public void onTick(long millisUntilFinished) {
}
@Override
public void onFinish() {
if ( activityReference.get().readingMyKad ) {
try {
activityReference.get().readingMyKad = false;
if (readMyKadObject.getStatus() == AsyncTask.Status.RUNNING) {
boolean bret = readMyKadObject.cancel(true);
Log.e(TAG,"readMyKadAsyncTask Timeout, cancel: " + bret);
}
} catch (Exception ignored) {
}
}
}
};
readMyKadCdt.start();
}
...............
但是在类readMyKad中,我需要从主模块LibModule中获取变量,例如activityReference.get()。readingMyKad。
不仅可以获取变量,还可以从LibModule设置和调用函数。我该怎么办,因为LibModule不是活动。
对不起,我的英语和标题。