android activities pdf

Document Sample
android activities pdf Powered By Docstoc
					               ACTIVITIES
                   &
                INTENTS


                       Copyright © 2012, apkdownloads.inl. All rights
Activities-1
                                                           reserved
                                        Activity
       • An Activity is a window that contains the user
         interface of your applications .
       • An application can have zero or more activities.
       • The main aim of an activity is to interact with the
         user.
       • From the moment the activity appears on the screen
         to the disappear , it goes through a no of stages.
       • This is called as Activity Life Cycle.
       • To create a new Activity , create a Java class that
         extends the Activity base class.
                android.app.Activity
       • The Default Activity which is generated by eclipse
         will have the following code:

                                                   Copyright © 2012, apkdownloads.inl. All rights
Activities-2
                                                                                       reserved
               Java code for Activity generated by eclipse
       package com.uclid.activities;
       import android.app.Activity;
       import android.os.Bundle;
       public class ActivitesTestActivity extends Activity {
         /** Called when the activity is first created. */
         @Override
       public void onCreate(Bundle savedInstanceState) {
         super.onCreate(savedInstanceState);
         setContentView(R.layout.main);
       }
       }


                                             Copyright © 2012, apkdownloads.inl. All rights
Activities-3
                                                                                 reserved
                             Activity’s .xml file
      <?xml version="1.0" encoding="utf-8"?>
      <LinearLayout
         xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:orientation="vertical" >

          <TextView
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:text="@string/hello" />

      </LinearLayout>



                                                   Copyright © 2012, apkdownloads.inl. All rights
Activities-4
                                                                                       reserved
                               AndroidManifest.xml
       <?xml version="1.0" encoding="utf-8"?>
       <manifest xmlns:android="http://schemas.android.com/apk/res/android"
         package="com.uclid.activities"
         android:versionCode="1"
         android:versionName="1.0" >

           <uses-sdk android:minSdkVersion="14" />

         <application
           android:icon="@drawable/ic_launcher"
           android:label="@string/app_name" >
           <activity
             android:name=".ActivitesTestActivity"
             android:label="@string/app_name" >
             <intent-filter>
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />
             </intent-filter>
           </activity>
         </application>
       </manifest>
                                                        Copyright © 2012, apkdownloads.inl. All rights
Activities-5
                                                                                            reserved
                            Creating Second Activity
       • We have discussed the steps for developing user
         Activity classes into our application.
       • Each Activity is a subclass of Activity Class.
       • Each Activity UI is designed by using its .xml file for
         layout management.
       • Each Activity should be configured in
         AndroidManifest.xml file.
       • There should be only one Activity declared with
         category
                android.intent.category.LAUNCHER
       • Remaining all activities should be declared with
         category
                android.intent.category.DEFAULT.

                                                    Copyright © 2012, apkdownloads.inl. All rights
Activities-6
                                                                                        reserved
                                                  INTENT
       • Every Android Application may have more than one
         activities.
       • Browsing the application, is navigating from one
         activity to another activity.
       • Navigation between the activities is done by using
         intent.
       • We have to create an object for Intent by using
                •   android.content.Intent
       • Constructors of Intent
               Constructor                             Description
               Intent()                                Creates an empty intent
               Intent(String action)                   Creates an Intent with the specified
                                                       action
               Intent(Context packageContext, Class)   Creates an intent for a specific content
                                                                  Copyright © 2012, apkdownloads.inl. All rights
Activities-7
                                                                                                      reserved
                                      Intent Filter

       • Intent Filter tag specifies the types of intents that an
         activity ,service or broadcast reciever can do.
       • An Intent Filter declares the capabilities of its parent
         components
               • What an Activity can do.
               • What a service can do.
               • What types of broadcasts a reciever can handle.
       • Most of the intent filters are described by its sub
         elements
               • <action>
               • <category>
               • <data>


                                                      Copyright © 2012, apkdownloads.inl. All rights
Activities-8
                                                                                          reserved
                                     <intent-filter>
<intent-filter>
               <action android:name="android.intent.action.MAIN" />
               <category android:name="android.intent.category.DEFAULT" />
 </intent-filter>
• <action> adds an action to the intent filter.
• <intent-filter> element must contains one or more <action>
   elements.
• <action> attributes:
       •  android:name : the name of the action. Some standard actions are
         defined in the Intent Class as ACTION_String Constants.
       • To assign one of these actions we prepend “android.intent.action.”
         to the String that follows ACTION_.
       • For Example, for ACTION_MAIN , use “android.intent.action.MAIN”.
       • Starts as a main entry point does not expect to receive the data.
                                                        Copyright © 2012, apkdownloads.inl. All rights
Activities-9
                                                                                            reserved
                                     <category> tag

       <category> :
                 adds a category name to an intent filter.

                Attribute                 Description
                 android:name             The name of the category.


                 Standard Categories are defined in the Intent class as
                  CATEGORY_name constants.
                 Assign this constant to prefix: android.intent.category.
                 For Example:
                 String value for CATEGORY_LAUNCHER is:
                 “android.intent.category.LAUNCHER”.



                                                            Copyright © 2012, apkdownloads.inl. All rights
Activities-10
                                                                                                reserved

				
DOCUMENT INFO
Description: Android tutorial with full Example, including Android UI Controls, layouts, Common application and Some FAQs, Android hello world example, android activity example, android source code to Eclipse IDE, button,textbox, password, checkbox, spinner,date picker, time picker, alert box, custom dialog, toast, imageview, imagebutton, LinearLayout, RelativeLayout, TableLayout, ListView, Gridview, Webview
BUY THIS DOCUMENT NOW PRICE: $19.99 100% MONEY BACK GUARANTEED
PARTNER parameshwar kamani