这是什么和Activity.this之间的差 [英] What's the difference between this and Activity.this

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

问题描述

例如

 意向意图=新的意图(这一点,SecondActivity.class);
 

  

日食错误:该方法setClass(背景下,类)的类型   意图是不适用的参数(FirstActivity.ClickEvent,   类)

 意向意图=新的意图(FirstActivity.this,SecondActivity.class);
 

但是,这是正确的。 任何人都可以解释这两个之间的区别? 谢谢你。

解决方案

指的是您当前对象。你的情况,你必须已经实施了一个内部​​类ClickEvent意向,并且那是什么它指向。

Activity.this 指向活动的您目前的情况。

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天全站免登陆