meaning of RuntimeException(“Stub!”) in Android

こ雲淡風輕ζ 提交于 2019-12-05 08:45:23

问题


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() there would be a call to onDestroy() method.

But what I found in this method (and in many others) was:

public void finish() {
    throw new RuntimeException("Stub!");
}

So WHERE Can I find the code that really destroys the Activity? Thanks!


回答1:


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.




回答2:


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.




回答3:


You are checking in .class not .java file.



来源:https://stackoverflow.com/questions/39913574/meaning-of-runtimeexceptionstub-in-android

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!