There are many more items which you use to build a good Android application. Apart from coding for the application, you take care of various other resources like static content that your code uses, such as bitmaps, colors, layout definitions, user interface strings, animation instructions, and more. These resources are always maintained separately in various sub-directories under res/ directory of the project.
This lesson will explain you how you can organize your application resources, specify alternative resources and access them in your applications.
You should place each type of resource in a specific subdirectory of your project's res/ directory. For example, here's the file hierarchy for a simple project:
The res/ directory contains all the resources in various subdirectories. Here we have an image resource, two layout resources, and a string resource file.
Your application should provide alternative resources to support specific device configurations. For example, you should include alternative drawable resources ( ie.images ) for different screen resolution and alternative string resources for different languages. At runtime, Android detects the current device configuration and loads the appropriate resources for your application.
To specify configuration-specific alternatives for a set of resources, follow the following steps:
Visit the Library for ebook and video tutorial.
During your application development you will need to access defined resources either in your code, or in your layout XML files. Following section explains how to access your resources in both the scenarios:
ACCESSING RESOURCES IN CODE
When your Android application is compiled, a R class gets generated, which contains resource IDs for all the resources available in your res/ directory. You can use R class to access that resource using sub-directory and resource name or directly resource ID.
Now if you will go through previous lesson once again where we explained Hello World Android Example, you will have better understanding on all the concepts explained in this lesson.
An activity represents a single screen with a user interface. For example, an email application might have one activity that shows a list of new emails, another activity to compose an email, and another activity for reading emails. If an application has more than one activity, then one of them should be marked as the activity that is presented when the application is launched.
If you have worked with C, C++ or Java programming language then you must have seen that your program starts from main( ) function. Very similar way, Android system initiates its program with in an Activity starting with a call on onCreate( ) callback method. There is a sequence of callback methods that start up an activity and a sequence of callback methods that tear down an activity as shown in the below Activity lifecycle diagram: (image courtesy : android.com )