What exactly does using the Application Context mean?

前端 未结 2 1234
自闭症患者
自闭症患者 2020-12-05 20:47

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 t

2条回答
  •  庸人自扰
    2020-12-05 21:17

    For the tasks you're working with here, you'll be using the Java code that defines the behavior of the application, not the XML files that define resources and layouts or the AndroidManifest.xml file that declares basic application properties.

    If you're working with Hour 3 of the Sam's Teach Yourself... book, then you need to open the src\com.androidbook.droid1\DroidActivity.java file. In general, you would need src\\.java. When you open that file, you'll see a class (in this case, DroidActivity) that extends Activity and already has the onCreate() callback method. Anything that you want to happen during onCreate() goes inside that method. Other callback methods can be added inside the activity class. To see an example that has all the lifecycle callbacks (but doesn't do anything in them), look here.

    A logging tag is just a string. You can declare it, for example, as a private static final String inside the activity class.

    If there's confusion about where methods belong, where and how to define variables or constants, how to call methods, how to use classes, and so forth, then it might be best to go through an introductory Java text before starting with Android. There are plenty of free resources available for that.

提交回复
热议问题