这到底是使用应用程序上下文是什么意思?上下文、应用程序

2023-09-12 09:30:22 作者:断情亡音

我是新来的这一点,我很抱歉,如果这是一个非常愚蠢的问题。我只是想澄清的事情。我的书上说我可以使用 getApplicationContext()方法来检索应用程序上下文的过程。我真的不知道在哪里键入这个或怎么做任何它。我可以去层次,但我做的一切有脚本的内容。也是在那里,我会写活动回调,在main.xml中?一个运动要我一个记录标记添加到我的项目,但我不知道如何做到这一点。确切的文字说:

I'm new to this and I'm sorry if this is a really dumb question. I'm just trying to clarify things. My book says I can retrieve application context for process by using the getApplicationContext() method. I just really don't know where to type this or what to do with any of it. I can go to the hierarchy but what do I do with all the script there. Also where would I write Activity Callbacks, in the main.xml? An exercise wants me to add a logging tag to my project but I'm not sure how to do this. The exact text says:

内的onCreate()回调方法,使用Log.i()方法中添加信息记录的信息。

"Within the onCreate() callback method, add an informational logging message, using the Log.i() method."

和其他练习说来:

实施一些除的onCreate(活动回调方法),如ONSTART()。添加日志消息到每个回调方法,然后运行该应用程序正常。

"Implement some of the Activity callback methods in addition to onCreate(), such as onStart(). Add a log message to each callback method and then run the application normally".

由于这些看似基本的问题,可以有人请帮助我。

As these seem like basic questions, can someone please help me.

我使用了Android SDK和Eclipse。我做了Hello World应用程序,但我不知道该怎么做上下文或获取资源。请帮帮忙!

I am using the Android SDK, and Eclipse. I have made the Hello World application, but I have no idea what to do with Context or Retrieving resources. Please help!

推荐答案

我想给你的第一条规则:如果你不知道为什么你需要它,你可能不需要它。当你需要一个环境中使用你的活动对象的语境。

The first rule I would give you: if you don't know why you need it, you probably don't need it. Use your activity object as the Context when you need a context.

是作业类,你谈论的回调。该应用程序基础描述了一个活动是:http://developer.android.com/guide/topics/fundamentals.html#Components

The callbacks you talk about are on the Activity class. The Application Fundamentals describes what an Activity is: http://developer.android.com/guide/topics/fundamentals.html#Components

您想要使用getApplicationContext唯一的一次()是当你需要一个背景下,存在一个Activity类(或其它部件)的生命周期之外。你想找到在哪里,这是需要的特定情况下的文档,还有很多漂浮。比如这个人是在Android文档的一部分:http://android-developers.blogspot.de/2009/01/avoiding-memory-leaks.html

The only time you want to use getApplicationContext() is when you need a Context that exists outside of the lifecycle of an Activity class (or other component). You'll want to find documentation on specific cases where this is desired, there is a lot floating around. For example this one is part of the Android documentation: http://android-developers.blogspot.de/2009/01/avoiding-memory-leaks.html