Android, What does this in Intent(this, …) mean [closed]

半城伤御伤魂 提交于 2019-12-31 07:43:06

问题


I am creating an Intent in android SDK but i don't know when to use the "this" value as argument or something else.. Can someone explain what "this" is used for? I know it means something like the object it's currently in but i don't know what the value is used for.

tnx.


回答1:


this is used to refer current activity in case of Intent




回答2:


Intent probably takes an interface as the first parameter and your object this has an implementation of that interface.




回答3:


you're making an explicit intent which takes two parameters: The context implementing the class and the activity (class) to be opened by the intent for example:

Intent i = new Intent(this, AnotherActivity.class);

the this is specifying the context implementing the class. take a look at the documentation for intents : http://developer.android.com/reference/android/content/Intent.html#Intent(android.content.Context, java.lang.Class)

It will also be able to show you the difference between an implicit and explicit intent



来源:https://stackoverflow.com/questions/18785957/android-what-does-this-in-intentthis-mean

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