"is it safe to finish an android activity from a background thread?" Code Answer

2

no, it is not.

the code uses at least one variable, mfinished, without synchronization. full stop.

   public void finish() {
    if (mparent == null) {
        int resultcode;
        intent resultdata;
        synchronized (this) {
            resultcode = mresultcode;
            resultdata = mresultdata;
        }
        if (false) log.v(tag, "finishing self: token=" + mtoken);
        try {
            if (resultdata != null) {
                resultdata.setallowfds(false);
            }
            if (activitymanagernative.getdefault()
                .finishactivity(mtoken, resultcode, resultdata)) {
                mfinished = true;
            }
        } catch (remoteexception e) {
            // empty
        }
    } else {
        mparent.finishfromchild(this);
    }
}
By Nagesh Andani on July 16 2022

Answers related to “is it safe to finish an android activity from a background thread?”

Only authorized users can answer the Search term. Please sign in first, or register a free account.