这之间的区别是什么,的getContext()和getActivity()? [英] What is the difference between this, getContext() and getActivity()?

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

问题描述

我很困惑与所有这些是我们应该在哪里使用它们的用法。

解决方案

本 - 收益的自参考
的getContext() - 返回语境
getActivity() - 返回活动

上下文

顾名思义,应用/对象的当前状态其上下文。它让新创建的对象明白什么已经持续。通常你调用它来获取有关您的程序(活动,封装/应用),另一部分信息。

活动

活动是支持屏幕或用户界面在Java code。换句话说,在用户界面的积木是活性。 Activity类是Android和具有用户界面必须继承它创建窗口每个应用程序pre定义的类。活动重新presents一个Android应用程序,如的presentation层用户看到它的屏幕。 Android应用程序可以有多个活动,并可以在它们之间的应用程序运行时进行切换。

  

注:活动扩展语境。上下文不是活动。

I am very confused with the usage of all these that where should we use them.

解决方案

this - return self reference
getContext() - return Context
getActivity() - return Activity

Context.

As the name suggests, its the context of current state of the application/object. It lets newly created objects understand what has been going on. Typically you call it to get information regarding another part of your program (activity, package/application)

Activity

Activity is a Java code that supports a screen or UI. In other words, building block of the user interface is the activity. Activity class is a pre-defined class in Android and every application which has UI must inherit it to create window. Activity represents the presentation layer of an Android application, e.g. a screen which the user sees. An Android application can have several activities and it can be switched between them during runtime of the application.

Note : Activity extends Context. Context not a Activity.

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

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