Showing posts with label Manifest. Show all posts
Showing posts with label Manifest. Show all posts

Sunday 2 November 2014

Android Tutorial 26 : Activity In Android

An activity presents a visual user interface for one focused endeavor the  user can undertake.
An application might consist of just one activity or many.
Each one is implemented as a subclass of the Activity base class

An Activity is an application component that provides a screen with which users can interact in order to do something, such as dial the phone, take a photo, send an email, or view a map. Each activity is given a window in which to draw its user interface.  

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. Each activity can then start another activity in order to perform different actions. Each time a new activity starts, the previous activity is stopped, but the system preserves the activity in a stack (the "back stack"). When a new activity starts, it is pushed onto the back stack and takes user focus.. 


Declaring Activity In Manifest



<manifest ... >
  <application ... >
      <activity android:name=".ExampleActivity" />
      ...
  </application ...> 
</manifest >
 
 
 

Using Intent Filters  In Activity Tag

<activity android:name=".ExampleActivity" android:icon="@drawable/app_icon">
    <intent-filter>
        <action android:name="android.intent.action.MAIN" />
        <category android:name="android.intent.category.LAUNCHER" />
    </intent-filter>
</activity> 
 
The <action> element specifies that this is the "main" entry point to the application.
 The <category> element specifies that this activity should be listed in the
system's application launcher (to allow users to launch this activity). 


Starting An Activity:



You can start another activity by calling startActivity(), passing it an Intent that describes the activity you want to start. The intent specifies either the exact activity you want to start or describes the type of action you want to perform

 
     Intent intent = new Intent(this, SignInActivity.class);
startActivity(intent); 

Implementing the lifecycle callbacks:

When an activity transitions into and out of the different states described above, it is notified through various callback methods. All of the callback methods are hooks that you can override to do appropriate work when the state of your activity changes. The following skeleton activity includes each of the fundamental lifecycle methods:

public class ExampleActivity extends Activity {
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        // The activity is being created.
    }
    @Override
    protected void onStart() {
        super.onStart();
        // The activity is about to become visible.
    }
    @Override
    protected void onResume() {
        super.onResume();
        // The activity has become visible (it is now "resumed").
    }
    @Override
    protected void onPause() {
        super.onPause();
        // Another activity is taking focus (this activity is about to be "paused").
    }
    @Override
    protected void onStop() {
        super.onStop();
        // The activity is no longer visible (it is now "stopped")
    }
    @Override
    protected void onDestroy() {
        super.onDestroy();
        // The activity is about to be destroyed.
    }
}

Saturday 1 November 2014

Android Tutorial 2 : Understanding Android Manifest File

Android Manifest file is at the heart of the (structure of) android app. If you do not pay attention to androidmanifest.xml file and its role, you will not be able to design and develop your app and further you will not be able to reuse the platform and its services.
To put it succinctly, the Android Manifest file lists out all the modules of your android application. The platform (android) regulates the life cycle of your app using intent, intent filters, activities, content providers, intent receivers, your app’s permissions and even instrumentation (enterprise enablement) for your app using the manifest file

Every Android application must have an AndroidManifest.xml file. The manifest presents essential information about the application to the Android system, information the system must have before it can run any of the application's code. Among other things, the manifest does the following:
  • It names the Java package for the application. The package name serves as a unique identifier for the application.
  • It describes the components of the application — the activities, services, broadcast receivers, and content providers that the application is composed of. It names the classes that implement each of the components and publishes their capabilities (for example, which Intent messages they can handle). These declarations let the Android system know what the components are and under what conditions they can be launched.
  • It determines which processes will host application components.
  • It declares which permissions the application must have in order to access protected parts of the API and interact with other applications.
  • It also declares the permissions that others are required to have in order to interact with the application's components.
  • It lists the Instrumentation classes that provide profiling and other information as the application is running. These declarations are present in the manifest only while the application is being developed and tested; they're removed before the application is published.
  • It declares the minimum level of the Android API that the application requires.
  • It lists the libraries that the application must be linked against.
Elements of manifest File:

All the elements that can appear in the manifest file are listed below . These are the  elements that you can add in manifest file ; you cannot add your own elements or attributes.


 
 You can add all or some of the elements depending on your requirement
See the detail description of manifest file and elements  here