完成()和ActivityName.this.finish()之间的区别是什么? [英] What is the difference between finish() and ActivityName.this.finish()?

查看:1903
本文介绍了完成()和ActivityName.this.finish()之间的区别是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有间任何区别完成() ActivityName.this.finish()?如果我们有名字的活动 SampleActivity ,我们可以通过调用完成它完成() SampleActivity.this.finish()。有什么区别?

Is there any difference between finish() and ActivityName.this.finish()? If we have activity with name SampleActivity, we can finish it by calling finish() and by SampleActivity.this.finish(). What is the difference?

推荐答案

在大多数情况下是同样的,除非你是一个内部类中。

Most of the time it's the same except if you are inside an inner class.

在这种情况下,第二符号用于消除歧义调用含有活性的方法。

In that case the second notation is used to disambiguate calls to the containing activity's methods.

例如:

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    finish(); // the activity's finish()

    new Runnable() {

        private void finish() {
            ...
        }

        @Override
        public void run() {
            SampleActivity.this.finish(); // the activity's finish()
            finish(); // the runnable's finish()
        }
    };

    new Runnable() {

        @Override
        public void run() {
            SampleActivity.this.finish(); // the activity's finish()
            finish(); // the activity's finish() (because the inner class doesn't hide it
        }
    };
}

这篇关于完成()和ActivityName.this.finish()之间的区别是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆