这个和Activity.this有什么区别 [英] What's the difference between this and Activity.this

查看:20
本文介绍了这个和Activity.this有什么区别的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

例如

Intent intent = new Intent(this, SecondActivity.class);

<块引用>

eclipse 错误:方法 setClass(Context, Class) 中的类型意图不适用于参数 (FirstActivity.ClickEvent,类)

Intent intent = new Intent(FirstActivity.this, SecondActivity.class);

但这将是正确的.任何人都可以解释这两者之间的区别吗?谢谢.

解决方案

this 指的是您当前的对象.在您的情况下,您必须在内部类 ClickEvent 中实现了意图,这就是它指向的内容.

Activity.this 指向您当前所在的 Activity 的实例.

For example

Intent intent = new Intent(this, SecondActivity.class);

eclipse error: The method setClass(Context, Class) in the type Intent is not applicable for the arguments (FirstActivity.ClickEvent, Class)

Intent intent = new Intent(FirstActivity.this, SecondActivity.class);

But that will be correct. Anybody can explain the difference between those two ? Thanks.

解决方案

this refers to your current object. In your case you must have implemented the intent in an inner class ClickEvent, and thats what it points to.

Activity.this points to the instance of the Activity you are currently in.

这篇关于这个和Activity.this有什么区别的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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