java Android 中 RuntimeException("Stub!") 的含义
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/39913574/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
meaning of RuntimeException("Stub!") in Android
提问by Alex Mawashi
I was surfing in Android code because I wanted to see what is into Activity.finish() method.
我正在浏览 Android 代码,因为我想看看 Activity.finish() 方法中有什么。
I just wanted to have the confirmation that in Activity.finish()
there would be a call to onDestroy()
method.
我只是想确认Activity.finish()
那里会调用onDestroy()
方法。
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!
那么在哪里可以找到真正破坏Activity的代码呢?谢谢!
采纳答案by hakim
回答by Tim
I don't know where you looked, but the code for finish()
is this
我不知道你在哪里看的,但代码finish()
是这样的
/**
* 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
这里重要的是ActivityManagerNative.getDefault().finishActivity
你可以在这个文件的第 3359 行找到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.
如果你想更深入地潜水,你可以沿着小路走。
回答by Mundroid
You are checking in .class not .java file.
您正在签入 .class 而不是 .java 文件。