调用CallBack();需要使用时起作用

时间:2018-10-19 05:20:45

标签: android multithreading callback

当我需要使用CallBack()时如何再次打电话?

目前,我正在通过此方式致电CallBack()

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

如果我写错了,请纠正我,但是这会消耗我的RAM消耗吗?。由于出现致命错误Fatal signal 11 (SIGSEGV) at 0x0000000b (code=1), thread 2347 (i.mikee.jti_pos)。我们的设备只有1 GB的RAM,这就是为什么我非常小心的原因线程侧。

这是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();
        }
    }
}

在Android Studio上浏览,有一个功能callBackThreadHome.run()。不合适吗?。

1 个答案:

答案 0 :(得分:1)

只需将“ CallBackThreadHome”保存在全局变量中,您就可以在需要时重复使用它。

RAM的“吃”与线程系统无关,而仅取决于您在其中进行的工作,但是回调并不意味着“多线程”,而只是在特定时间从另一段代码中调用的方法。

SIGSEGV错误具有特定含义,但这是另一个故事/问题。