Pages

Monday, May 24, 2010

What Makes an Android Application?

There are six components that provide the building blocks for your applications:

  • Activities : Your application’s presentation layer. Every screen in your application will be an extension of the Activity class. Activities use Views to form graphical user interfaces that display information and respond to user actions. In terms of desktop development, an Activity is equivalent to a Form. You’ll learn more about Activities later in this chapter.

  • Services : The invisible workers of your application. Service components run invisibly, updating your data sources and visible Activities and triggering Notifi cations. They’re used to perform regular processing that needs to continue even when your application’s Activities aren’t active or visible.                                            

  • Content Providers : A shareable data store  Content Providers are used to manage and share application databases. Content Providers are the preferred way of sharing data across application boundaries. This means that you can confi  gure your own Content Providers to permit access from other applications and use Content Providers exposed by others to access their stored data. Android devices include several native Content Providers that expose useful databases like contact information. 

  • Intents : A simple message-passing framework. Using Intents, you can broadcast messages system-wide or to a target Activity or Service, stating your intention to have an action performed. The system will then determine the target(s) that will perform any actions as appropriate.

  • Broadcast Receivers     Intent broadcast consumers. By creating and registering a Broadcast Receiver, your application can listen for broadcast Intents that match specific filter criteria. Broadcast Receivers will automatically start your application to respond to an incoming Intent, making them ideal for event-driven applications.
  • Notifications    A user notifi  cation framework. Notifi cations let you signal users without stealing focus or interrupting their current Activities. They’re the preferred technique for getting a user’s attention from within a Service or Broadcast Receiver. For example, when a device receives a text message or an incoming call, it alerts you by fl ashing lights, making sounds, displaying icons, or showing dialog messages. You can trigger these same events from your own applications using Notifications.

Thursday, May 20, 2010

Download Best android books

Download android book
 .Beginning Android

Best android book in my opinion.
Professional Android Application Development (Wrox Programmer to Programmer)


Android play video without controls



  • Here we are going to play a 3gp video in our Android application.



  • The important point we have to note is that video doesn’t plays when placed in the raw folder.Hence it has to be placed in the SDCARD itself.
    So lets begin this interesting topic.
    Ok, let us first insert our video:


    • You can get a short 3gp video from net (I got it from http://www.free-3gp-video.com).


    • In eclipse open perspective DDMS(Window –> Open Perspective –> DDMS) .


    • In DDMS perspective open view File Explorer(Window –> Show View –> File Explorer).


    • Also open Device view (Window –> Show View –> Device) and click the emulator you want to use(if emulator is not running then run a emulator with a sdcard option).


    • Then in File Explorer view navigate the tree shown and click sdcard node.


    • There are two buttons on the top right hand side of File Explorer as shown below







      • Click the button “Push a file onto the device” and in the file chooser navigate and choose the 3gp video.It should appear in the list of sdcard.(If not able to insert, check whether SDCARD is emulated in the emulator , in 1.5 sdk while creating a new Emulator there is a option of sdcard , insert 128M in the textbox next to it).


      • Ok, back to our code, open java perspective(Window –>Show View –> Java) and open layout file Main.xml.
    Replace the its content with following contents:
    ( I will use "(" in place of  "<" )
    **********************************************
    (?xml version="1.0" encoding="utf-8"?>
    (FrameLayout android:id="@+id/FrameLayout01" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" 
    xmlns:android="http://schemas.android.com/apk/res/android">
    (VideoView android:id="@+id/myvideo" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content">
    (/VideoView>
    (/FrameLayout>

    **********************************************
    Marie Claire (2-year)
    • Now create your main activity class :


    public class SeeVideo extends Activity {
        /** Called when the activity is first created. */
        @Override
        public void onCreate(Bundle savedInstanceState) {
         super.onCreate(savedInstanceState);

         // set the view to our layout file

         setContentView(R.layout.main);
         // Video view: to view our video
         VideoView video = (VideoView) findViewById(R.id.myvideo);

         //set your video path(in this case squirrel-playing-football.3gp)
         video.setVideoPath("/sdcard/squirrel-playing-football.3gp");
         video.start();
        }
    }
    *********************************************

    • Run the application and the video runs as shown below:


    Wednesday, May 19, 2010

    Android Listview Example


    In Android, Listview is used to show a list of items in a vertically scrolling list.
    For instance, in a Registration form when we are selecting professions a list of items will be displayed. We can use Listview to display the list of items.
    Your XML file should look like
    *********************************************
    xml version="1.0" encoding="utf-8"?>
    2<LinearLayout android:id="@+id/LinearLayout01"
    3 android:layout_width="fill_parent"
    4 android:layout_height="fill_parent"
    6 <ListView android:id="@+id/ListView01"
    7 android:layout_width="wrap_content"
    8 android:layout_height="wrap_content" />
    9LinearLayout>
    Your Java code looks like
    01public class ListviewExample extends Activity
    02{
    03private ListView lv1;
    04private String lv_arr[]={"Android","iPhone","BlackBerry","AndroidPeople"};
    05@Override
    06public void onCreate(Bundle icicle)
    07{
    08super.onCreate(icicle);
    09setContentView(R.layout.main);
    10lv1=(ListView)findViewById(R.id.ListView01);
    11// By using setAdpater method in listview we an add string array in list.
    12lv1.setAdapter(new ArrayAdapter(this,android.R.layout.simple_list_item_1 , lv_arr));
    13}
    14}



    The output will look like
    listviewexample