Quantcast
Channel: Active questions tagged react-native+android - Stack Overflow
Viewing all articles
Browse latest Browse all 28468

getting variable from native module in sub class

$
0
0

I have LibModule.java set as native module in 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();
        }
     ...............

but in class readMyKad, i need to get variables from my main module LibModule such as activityReference.get().readingMyKad.

not just get the variable but also set and call function from LibModule. how can i do that because LibModule is not an activity.

im sorry for my english and the title.


Viewing all articles
Browse latest Browse all 28468

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>