Recall CallBack(); function when need to use

0

How can I call my CallBack() again when I need to use it?

Currently, I'm calling my CallBack() by doing this

CallBackThreadHome callBackThreadHome = new CallBackThreadHome();
    callBackThreadHome.start();

Correct me if I'm wrong, but It will eat my RAM consumption?.Because I'm getting a Fatal Error Fatal signal 11 (SIGSEGV) at 0x0000000b (code=1), thread 2347 (i.mikee.jti_pos) .Our device only has 1 GB of RAM that's why I'm very careful on the Threading side.

This is the callBackThreadHome();

class CallBackThreadHome extends Thread {
    @Override
    public void run() {
        try {
            RFCardInterface.waitForCardPresent(RFCardInterface.CONTACTLESS_CARD_MODE_AUTO, 1, -1);
            if (RFCardInterface.isCallBackCalled &&
                    RFCardInterface.notifyEvent.eventID == RFCardInterface.CONTACTLESS_CARD_EVENT_FOUND_CARD) {

                IDCatcher = StringUtility.ByteArrayToString(RFCardInterface.notifyEvent.eventData,
                        RFCardInterface.notifyEvent.eventData.length);

                IDCatcher = IDCatcher.substring(9, 21);
                IDCatcher = IDCatcher.replace(" ", "");

                Cursor c = dbhelper.getReadableDatabase().rawQuery("select is_arrived,is_closed from trans_settings order by _id desc limit 1", null);

                if (c != null && c.moveToFirst()) {
                    String is_arrived = c.getString(0);
                    String is_closed = c.getString(1);

                    if (is_arrived.equals("0") && is_closed.equals("0")) {
                        SearchEmp();
                    } else if (is_arrived.equals("1") && is_closed.equals("0")) {
                        SearchEmp_isArrived();
                    } else if (is_arrived.equals("1") && is_closed.equals("1")) {
                        SearchEmp_isClosed();
                    }
                    c.close();
                }
            }
        } catch (Throwable e) {
            e.printStackTrace();
        }
    }
}

browsing on Android Studio, There has a function callBackThreadHome.run(). Isn't it appropriate?.

android
multithreading
callback
asked on Stack Overflow Oct 19, 2018 by Rubick • edited Oct 19, 2018 by Rubick

1 Answer

1

Just save the "CallBackThreadHome" in a Global variable and you can reuse it whenever you want.

RAM "eating" doesn't depends of Threading system but only of the WORK you do INSIDE it, however callback doesn't means "Multithreading" but just a method that is called at some specific time from another piece of code.

The SIGSEGV error has a specific meaning, but it's another story/question.

answered on Stack Overflow Oct 19, 2018 by emandt

User contributions licensed under CC BY-SA 3.0