meaning of RuntimeException(“Stub!”) in Android

前端 未结 2 2054
星月不相逢
星月不相逢 2021-02-11 14:38

I was surfing in Android code because I wanted to see what is into Activity.finish() method.

I just wanted to have the confirmation that in Activity.finish()

相关标签:
2条回答
  • 2021-02-11 15:19

    I don't know where you looked, but the code for finish() is this

    /**
     * Call this when your activity is done and should be closed.  The
     * ActivityResult is propagated back to whoever launched you via
     * onActivityResult().
     */
    public void finish() {
        finish(DONT_FINISH_TASK_WITH_ACTIVITY);
    }
    

    which calls the private implementation

    /**
     * Finishes the current activity and specifies whether to remove the task associated with this
     * activity.
     */
    private void finish(int finishTask) {
        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.prepareToLeaveProcess(this);
                }
                if (ActivityManagerNative.getDefault()
                        .finishActivity(mToken, resultCode, resultData, finishTask)) {
                    mFinished = true;
                }
            } catch (RemoteException e) {
                // Empty
            }
        } else {
            mParent.finishFromChild(this);
        }
    }
    

    Important here is ActivityManagerNative.getDefault().finishActivity which you can find at line 3359 in this file https://android.googlesource.com/platform/frameworks/base/+/master/core/java/android/app/ActivityManagerNative.java

    If you want to dive deeper, you can just follow the trail.

    0 讨论(0)
  • 2021-02-11 15:40

    This is because source code is not found in SDK. To see the source code, you need to download source for Android SDK, so Android studio can display the respective code.

    0 讨论(0)
提交回复
热议问题