这之间的区别是什么,的getContext()和getActivity()?区别、getContext、getActivity

2023-09-12 05:27:55 作者:久念成疾,久病成医

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

解决方案

本 - 收益的自参考 的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.

解决方案 什么是GET和POST

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.