HI THIS TOUTORIAL WILL HELP FULL FOR STARTUP IN ANDROID CREATED BY NAVEENRAJU
ANDROID BASICS EXPLINATIONS BY NAVEENRAJU
Android Basic
|
|
Application fundamentals:
Android applications are written in the Java programming language. The Android SDK tools compile the code—along with any data and resource files. All Code resides in a single file that is apk file (android package file).apk file is use to install the app on device .
Each Android application lives in its own world.
The Android operating system is a multi-user Linux system in which each application is a different user.
By default, every application runs in its own Linux process. Android starts the process when any of the application’s code needs to be executed, and shuts down the process when it’s no longer needed and system resources are required by other applications.
Each process has its own Java virtual machine (VM), so application code runs in isolation from the code of all other applications.
By default, each application is assigned a unique Linux user ID. Permissions are set so that the application’s files are visible only that user, only to the application itself — although there are ways to export them to other applications as well.
Application Components
Application components are the essential building blocks of an Android application. Each component is a different point through which the system can enter your application.
There are four different types of application components. Each type serves a distinct purpose and has a distinct lifecycle that defines how the component is created and destroyed.
Here are the four types of application components:
1) Activities
2) Services
3)Content providers
4)Broadcast receivers
1) Activities:
An activity provides a user interface for a single screen in your application. Activities can move into the background and then be resumed with their state restored. An application usually consists of multiple activities that are loosely bound to each other. Typically, one activity in an application is specified as the “main” activity, which is presented to the user when launching the application for the first time. If an application is composed of several screens, it has an activity for each screen. when new activity starts a new activity starts, the previous activity is stopped, but the system preserves the activity in a stack.
A view hierarchy is placed within an activity's window by the
Activity.setContentView() method. The content view is the View object at the root of the hierarchy. (See the separate User Interface document for more information on views and the hierarchy.)<?xml version="1.0" encoding="utf-8"?>
<manifest . . . >
<application . . . >
<activity android:name="com.example.project.FreneticActivity"
android:icon="@drawable/small_pic.png"
android:label="@string/freneticLabel"
. . . >
</activity>
. . .
</application>
</manifest>
2) Services:
A service is an Android application component that runs in background and has no visual UI. Services are used to perform the processing parts of your application in the background. While the user is working on the foreground UI, services can be used to handle the processes that need to be done in the background. A service can be started by another Android application component such as an activity or other services and it will continue to run in the background even after the user switches to another application. Thus services are less likely to be destroyed by Android system to free resources, than Activities.
There are two types of services in Android:
Like activities and the other components, services run in the main thread of the application process. So that they won't block other components or the user interface, they often spawn another thread for time-consuming tasks (like music playback).
3)Content Providers:
Content Provider are used to share data among several applications. You can store the data in the file system, an SQLite database, on the web, or any other persistent storage location your application can access. Then through content providers other applications are able to query, access or even modify the data you’ve created, as long as your content provider allows it.
ContactsContract.Data ) to read and write information about a particular person.
Content providers are also useful for reading and writing data that is private to your application and not shared. For example, the Note Pad sample application uses a content provider to save notes.
A content provider is implemented as a subclass of
ContentProvider and must implement a standard set of APIs that enable other applications to perform transactions. For more information, see the Content Providers developer guide.
4)Broadcast receivers:
A broadcast receiver is a component that does nothing but receive and react to broadcast announcements. Many broadcasts originate from the system—for example, a broadcast announcing that the screen has turned off, the battery is low, or a picture was captured and other applications can receive by using Broadcast receiver.
An application can have any number of broadcast receivers to respond to any announcements it considers important. All receivers extend the BroadcastReceiver base class.
Broadcast receivers do not display a user interface. However, they may start an activity in response to the information they receive, or they may use the NotificationManager to alert the user. Notifications can get the user's attention in various ways — flashing the backlight, vibrating the device, playing a sound, and so on. They typically place a persistent icon in the status bar, which users can open to get the message.
Activating Components:
Intents: Intents are the activating components. The components — activities, services, and broadcast receivers — are activated by asynchronous messages called intents. An intent is an object that holds the content of the message. There are two types of Intents in Android:
<?xml version="1.0" encoding="utf-8"?>
<manifest . . . >
<application . . . >
<activity android:name="com.example.project.FreneticActivity"
android:icon="@drawable/small_pic.png"
android:label="@string/freneticLabel"
. . . >
<intent-filter . . . >
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
<intent-filter . . . >
<action android:name="com.example.project.BOUNCE" />
<data android:mimeType="image/jpeg" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
. . .
</application>
</manifest>
For broadcast receivers, the intent simply defines the announcement being broadcast (for example, a broadcast to indicate the device battery is low includes only a known action string that indicates "battery is low").
The other component type, content provider, is not activated by intents. Rather, it is activated when targeted by a request from a
ContentResolver . The content resolver handles all direct transactions with the content provider so that the component that's performing transactions with the provider doesn't need to and instead calls methods on the ContentResolver object. This leaves a layer of abstraction between the content provider and the component requesting information (for security).
There are separate methods for activating each type of component:
For more information about using intents, see the Intents and Intent Filters document. More information about activating specific components is also provided in the following documents: Activities, Services,
BroadcastReceiver and Content Providers.
The Manifest File:
Every application must have an AndroidManifest.xml file in its root directory.
AndroidManifest.xml is a powerful file in the Android platform that allows you to describe the functionality and requirements of your application to Android. The manifest is a structured XML file and is always named AndroidManifest.xml for all applications. It does a number of things:
Please ensure the manifest is packaged with your app and includes the following elements and data:
<?xml version="1.0" encoding="utf-8"?>
<manifest . . . >
<application . . . >
<activity android:name="com.example.project.FreneticActivity"
android:icon="@drawable/small_pic.png"
android:label="@string/freneticLabel"
. . . >
</activity>
. . .
</application>
</manifest>
In the
<application> element, the android:icon attribute points to resources for an icon that identifies the application.
In the
<activity> element, the android:name attribute specifies the fully qualified class name of theActivity subclass and the android:label attributes specifies a string to use as the user-visible label for the activity.
You must declare all application components this way:
Activities, services, and content providers that you include in your source but do not declare in the manifest are not visible to the system and, consequently, can never run. However, broadcast receivers can be either declared in the manifest or created dynamically in code (as
BroadcastReceiver objects) and registered with the system by calling registerReceiver() .
For more about how to structure the manifest file for your application, see the The AndroidManifest.xml Filedocumentation.
|