Friday 30 January 2015

LIST VIEW USING BASE ADAPTER

MainActivity

 package com.example.baseadapter;
import java.util.ArrayList;
import java.util.List;

import android.app.Activity;
import android.content.ContentResolver;
import android.content.Context;
import android.database.Cursor;
import android.os.Bundle;
import android.provider.ContactsContract;
import android.widget.ListView;

public class MainActivity extends Activity {

    
  
    List<String> names=new ArrayList<String>();
    List<String> phoneNumber=new ArrayList<String>();
  

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        readAllContacts();
    }

    private void readAllContacts() {
      
        Context ctx=getApplicationContext();
      
        ContentResolver cr = getContentResolver();
        Cursor cur = cr.query(ContactsContract.Contacts.CONTENT_URI, null,
                null, null, null);
        if (cur.getCount() > 0) {
            while (cur.moveToNext()) {
                String id = cur.getString(cur
                        .getColumnIndex(ContactsContract.Contacts._ID));
                String name = cur
                        .getString(cur
                                .getColumnIndex(ContactsContract.Contacts.DISPLAY_NAME));
                names.add(name);
              
                System.out.println("Name" + name);
                int hasPhoneNumber = Integer
                        .parseInt(cur.getString(cur
                                .getColumnIndex(ContactsContract.Contacts.HAS_PHONE_NUMBER)));

                if (hasPhoneNumber > 0) {

                    // Query and loop for every phone number of the contact

                    Cursor phoneCursor = cr.query(
                            ContactsContract.CommonDataKinds.Phone.CONTENT_URI,
                            null,
                            ContactsContract.CommonDataKinds.Phone.CONTACT_ID
                                    + " = ?", new String[] { id }, null);

                    phoneCursor.moveToNext();
                    String phomber = phoneCursor
                            .getString(phoneCursor
                                    .getColumnIndex(ContactsContract.CommonDataKinds.Phone.NUMBER));

                    phoneNumber.add(phomber);
                    System.out.println(" Phone number:" + phoneNumber);

                    //phoneCursor.close();
                }

                else {
                    phoneNumber.add("No Number");
                    System.out.println("No Number");
                }
            }
        }

      
      
      
        BaseAdp adp=new BaseAdp(names, phoneNumber, getApplicationContext());
        ListView lst=(ListView)findViewById(R.id.listView1);
        lst.setAdapter(adp);
      
      
      
      
    }
}


 Baseadapter Class


package com.example.baseadapter;

import java.util.List;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.Button;
import android.widget.TextView;
import android.widget.Toast;

public class BaseAdp extends BaseAdapter {

   
    List<String> names;
    List<String> phones;
    Context ctx;
   
    public BaseAdp(List<String> name, List<String> phn, Context cnt) {

       
        names=name;
        phones=phn;
        ctx=cnt;
       
    }

    @Override
    public int getCount() {
        // TODO Auto-generated method stub
        return phones.size();
    }

    @Override
    public Object getItem(int position) {
        // TODO Auto-generated method stub
        return null;
    }

    @Override
    public long getItemId(int position) {
        // TODO Auto-generated method stub
        return 0;
    }

    @Override
    public View getView(final int position, View convertView, ViewGroup parent) {
   
       
        LayoutInflater inflate=(LayoutInflater)ctx.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        convertView=inflate.inflate(R.layout.listitem, null);
       
        TextView txtName=(TextView)convertView.findViewById(R.id.textView1);
        TextView txtPhone=(TextView)convertView.findViewById(R.id.textView2);
       
        txtName.setText(names.get(position));
        txtPhone.setText(phones.get(position));
       
        Button btn=(Button)convertView.findViewById(R.id.button2);
        btn.setOnClickListener(new OnClickListener() {
           
            @Override
            public void onClick(View v) {
                Toast.makeText(ctx, position+"", Toast.LENGTH_SHORT).show();
               
                    names.remove(position);
                    phones.remove(position);
                    notifyDataSetChanged();
               
            }
        });
       
        return convertView;
       
    }

}


Thursday 29 January 2015

EXAMPLE OF ARRAY ADAPTER

MainActivity

package com.example.adapter;

import java.util.ArrayList;
import java.util.List;

import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemSelectedListener;
import android.widget.ArrayAdapter;
import android.widget.Spinner;

public class MainActivity extends Activity {

    @Override
    protected void onCreate(Bundle savedInstanceState)
    {
       
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
       
        ArrayList<String>cnt=new ArrayList<String>();
        cnt.add("India");
        cnt.add("Pakistan");
       
        Spinner spn=(Spinner)findViewById(R.id.spinner1);
        ArrayAdapter<String>adp=new ArrayAdapter<String>(MainActivity.this, android.R.layout.simple_spinner_item,cnt);
        spn.setAdapter(adp);
       
        final List<String>india=new ArrayList<String>();
        india.add("punjab");
        india.add("HP");
        india.add("MP");
       
       
       
       
        final List<String>pak=new ArrayList<String>();
        pak.add("p");
        pak.add("pl");
        pak.add("pp");
       
        spn.setOnItemSelectedListener(new OnItemSelectedListener(){
           

            @Override
            public void onItemSelected(AdapterView<?> arg0, View view,
                    int position, long id) {
               
                    if(position==0)
                    {
                        Spinner spn=(Spinner)findViewById(R.id.spinner2);
                        ArrayAdapter<String>adp=new ArrayAdapter<String>(MainActivity.this, android.R.layout.simple_spinner_item,india);
                        spn.setAdapter(adp);
                       
                        }
                    else if(position==1)
                    {
                        Spinner spn=(Spinner)findViewById(R.id.spinner2);
                        ArrayAdapter<String>adp1=new ArrayAdapter<String>(MainActivity.this, android.R.layout.simple_spinner_item,pak);
                        spn.setAdapter(adp1);
                       
            }}

            @Override
            public void onNothingSelected(AdapterView<?> arg0) {
                // TODO Auto-generated method stub
               
            }
           
        });
       
       }

    }

Xml File

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/container"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context="com.example.adapter.MainActivity"
    tools:ignore="MergeRootFrame" >

    <Spinner
        android:id="@+id/spinner1"
        android:layout_width="match_parent"
        android:layout_height="wrap_content" />
    <Spinner
        android:id="@+id/spinner2"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentLeft="true"
        android:layout_below="@+id/spinner1"
        android:layout_marginTop="15dp" />
</RelativeLayout>

Output

 

 


Monday 26 January 2015

ADAPTER

Adapters are the link between a set of data and the AdapterView that displays the data.
AdapterView
 
AdapterViews are ViewGroups that display child views given to it by an adapter. An example of an AdapterView is a ListView.
Adapters also provide the child views that display the data in the AdapterView. Adapters are responsible for supplying the data and creating the views representing each item  Adapters get the data and pass it, alongwith a child view, to the parent AdapterView which displays the child view and the data
The Android Framework has a set of native adapters that are easy to use. You can also create your own custom adapters if you wish.

Android Adapter:

How Android Adapter works


Adapters call the getView() method which returns a view for each item within the adapter view. The layout format and the corresponding data for an item within the adapter view is set in the getView() method. Now, it will be a performance nightmare if getView() returns a new View every time it is called. Creating a new view is very expensive in Android as you will need to loop through the view hierarchy (using the find ViewbyID () method) and then inflate the view to finally display it on the screen.It also puts a lot of pressure on the garbage collector. That is because when the user is scrolling through the list, if a new view is created; the old view (since it is not recycled) is not referenced and becomes a candidate to be picked up by the garbage collector. So what Android does is that it recycles the views and reuses the view that goes out of focus. 

Creating a custom Adapter View:

@Override

publicView getView(intitempos, View convertView, ViewGroup parent) {

//Check if the convertview is null, 
//if it is null it probably means that this is the first time the view has been displayed

if (convertView == null)

{

convertView = View.inflate (context,R.layout.list_content_layout, null);

}

//If it is not null, you can just reuse it from the recycler

TextView txtcontent = (TextView) convertView.findViewById(R.id.textView1);

<code>ImageView imgcontent = (ImageView) </code>convertView<code>.findViewById(R.id.imageView1); </code>

<code> </code>

<code>Paintings paintingcontent = content [itempos]; </code>

txtcontent.setText (paintingcontent.imagetitle);

imgcontent.setImageResource(paintingcontent.drawableresid);

// return the view for a single item in the listview

returnconvertView; 
 

Two of Android’s common adapters are:

ArrayAdapter

An ArrayAdapter is an adapter backed by an array of objects. It links the array to the Adapter View.
The default ArrayAdapter converts an array item into a String object putting it into a TextView. The text view is then displayed in the AdapterView (a ListView for example).
When you create the adapter, you need to supply the layout for displaying each array string. You can define your own or use one of Android’s, such as:
android.R.layout.simple_list_item_1
There are alternative constructors that you can use for more complex layouts. You can also display images instead of strings.

SimpleCursorAdapter

The SimpleCursorAdapter links the data contained in a Cursor to an Adapter View.
A cursor is a set of data. You usually get a cursor when you do a database query. The result of your query is contained in the cursor. The SimpleCursorAdapter binds the Cursor data to an Adapter View. You define a layout that controls how each row of data is displayed.
Each row’s view is populated using the column values of the corresponding row in the cursor.

Other useful Adapters

CursorAdapter

A CursorAdapter links a Cursor’s data to a List View. You must include the database’s _id column as it’s used in processing the list item’s selection.
The SimpleCursorAdapter is a subclass of CursorAdapter.
The SimpleCursorAdapter is easier to use while the CursorAdapter requires more work but allows more customization.

SimpleAdapter

The SimpleAdapter links static data to views defined in a layout file. You specify the data as an ArrayList of Maps. Each entry in the ArrayList will display as a row in a list.

BaseAdapter

The BaseAdapter is a common base class for an Adapter that can be used in a ListView and a Spinner.

ListAdapter

The ListAdapter links the data and a ListView displaying the data. The List View can display any data type provided it’s wrapped in a ListAdapter.

ListView

A ListView is a ViewGroup that displays a list of scrollable items. Items are inserted in the list using an Adapter.
The Adapter gets the data from a source such as an array, converts each item into a view and places the view in the list.

GridView

A GridView is a ViewGroup that display items in a 2 dimensional scrollable grid.
An Adapter gets the items from a data source, creates a view to enclose the item and then inserts the view in the parent grid.

Friday 23 January 2015

Alert Dialog

    How to display an alert box in Android. See flowing Steps :
  1. First, use the AlertDialog.Builder to create the alert box interface, like title, message to display, buttons, and button onclick function
  2. Later attach above builder to AlertDialog and display it.
  3. Done.
package com.Katchup.android;
 
import android.app.Activity;
import android.app.AlertDialog;
import android.content.Context;
import android.content.DialogInterface;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
 
public class MainActivity extends Activity {
 
 final Context context = this;
 private Button button;
 
 public void onCreate(Bundle savedInstanceState) {
 
  super.onCreate(savedInstanceState);
  setContentView(R.layout.main);
 
  button = (Button) findViewById(R.id.buttonAlert);
 
  // add button listener
  button.setOnClickListener(new OnClickListener() {
 
  @Override
  public void onClick(View arg0) {
 
   AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(
    context);
 
   // set title
   alertDialogBuilder.setTitle("Your Title");
 
   // set dialog message
   alertDialogBuilder
    .setMessage("Click yes to exit!")
    .setCancelable(false)
    .setPositiveButton("Yes",new DialogInterface.OnClickListener() {
     public void onClick(DialogInterface dialog,int id) {
      // if this button is clicked, close
      // current activity
      MainActivity.this.finish();
     }
      })
    .setNegativeButton("No",new DialogInterface.OnClickListener() {
     public void onClick(DialogInterface dialog,int id) {
      // if this button is clicked, just close
      // the dialog box and do nothing
      dialog.cancel();
     }
    });
 
    // create alert dialog
    AlertDialog alertDialog = alertDialogBuilder.create();
 
    // show it
    alertDialog.show();
   }
  });
 }
}

Wednesday 21 January 2015

Intent Example

MainActivity

In MainActivity we pass the intent to MainActivity1


package com.intent_navigation;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;

public class MainActivity extends Activity {
    private EditText name;
    private Button btn;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
       
        name =(EditText)findViewById(R.id.editText1);
         btn=(Button)findViewById(R.id.button1);
       
        abc();
       
       

    }
    public void abc()
    {
       
        btn.setOnClickListener(new OnClickListener() {
           
            @Override
            public void onClick(View arg0) {
               
               
                String myname=name.getText().toString();
   
               
                Intent obj=new Intent(MainActivity.this,MainActivity1.class);
                obj.putExtra("i", myname);
                startActivity(obj);
               
               
            }
        });
       
    }
 }

Xml File for MainActivity:-

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/container"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context="com.intent_navigation.MainActivity"
    tools:ignore="MergeRootFrame" >

    <EditText
        android:id="@+id/editText1"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:ems="10" >
       
</EditText>
    <Button
        android:id="@+id/button1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
         android:layout_below="@+id/editText1"
        android:text="Next activity"
        android:onClick="abc" />

</RelativeLayout>

MainActivity1

package com.intent_navigation;

import android.support.v7.app.ActionBarActivity;
import android.support.v7.app.ActionBar;
import android.support.v4.app.Fragment;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.ViewGroup;
import android.widget.EditText;
import android.widget.TextView;
import android.os.Build;

public class MainActivity1 extends ActionBarActivity {
    private TextView t1;
    String t2;
   

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main_activity1);
        t1=(TextView)findViewById(R.id.textView1);
       
         get();
}
    private void get()
    {
   
        String obj=getIntent().getStringExtra("i");
       

        t1.setText(""+obj);
       
    }
}



Xml File for MainActivity1:-

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/container"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context="com.intent_navigation.MainActivity1"
    tools:ignore="MergeRootFrame" >

    <TextView
        android:id="@+id/textView1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentLeft="true"
        android:layout_alignParentTop="true"
        android:layout_marginLeft="74dp"
        android:layout_marginTop="44dp"
        />

</RelativeLayout>





                                                                MainActivity

                                                                   MainActivity1








Display Alert on Back Button Pressed in Android

package com.example.alertonbackpressdemo;
import android.app.AlertDialog;
import android.content.DialogInterface;
import android.os.Bundle;
import android.app.Activity;
import android.view.Menu;

public class BackPressActivity extends Activity {
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
    }
    @Override
    public void onBackPressed() {
        AlertDialog.Builder builder = new AlertDialog.Builder(this);
        builder.setCancelable(false);
        builder.setMessage("Do you want to Exit?");
        builder.setPositiveButton("Yes", new DialogInterface.OnClickListener() {
            @Override
            public void onClick(DialogInterface dialog, int which) {
                //if user pressed "yes", then he is allowed to exit from application
                finish();
            }
        });
        builder.setNegativeButton("No",new DialogInterface.OnClickListener() {
            @Override
            public void onClick(DialogInterface dialog, int which) {
                //if user select "No", just cancel this dialog and continue with app
                dialog.cancel();
            }
        });
        AlertDialog alert=builder.create();
        alert.show();
    }   
}
In code we use "builder.setCancelable(false);" so that user can't cancel this dialog by pressing back again or touch outside the alert dialog box and dismiss it. So the user must press one of the options you have provided.
Next is "builder.setMessage("Do you want to Exit?");". Here we can write our own message that will be displayed to the user in an alert. 

"builder.setPositiveButton" will set a positive button in the left side. The parameter will accept the name of that button as we can see in code it is "Yes". The same thing is set for "builder.setNegativeButton". When we set these buttons, we need to pass a listener that will be fired when the user clicks one of the buttons.

Monday 19 January 2015

Intent

An  Android application can contain zero or more activities. If you want to navigate from one activity to another then android provides you Intent class. This class is available in android.content.Intent package. One of the most common uses for Intents is to start new activities.

An Intent is a messaging object you can use to request an action from another app component. Although intents facilitate communication between components in several ways, there are three fundamental use-cases:
  • To start an activity: An Activity represents a single screen in an app. You can start a new instance of an Activity by passing an Intent to startActivity(). The Intent describes the activity to start and carries any necessary data.
    If you want to receive a result from the activity when it finishes, call startActivityForResult(). Your activity receives the result as a separate Intent object in your activity's onActivityResult() callback. For more information, see the Activities guide.
  • To start a service: A Service is a component that performs operations in the background without a user interface. You can start a service to perform a one-time operation (such as download a file) by passing an Intent to startService(). The Intent describes the service to start and carries any necessary data.
    If the service is designed with a client-server interface, you can bind to the service from another component by passing an Intent to bindService(). For more information, see the Services guide.
  • To deliver a broadcast: A broadcast is a message that any app can receive. The system delivers various broadcasts for system events, such as when the system boots up or the device starts charging. You can deliver a broadcast to other apps by passing an Intent to sendBroadcast(), sendOrderedBroadcast(), or sendStickyBroadcast().

Intent Type

There are two types of intents: 

Explicit intents:- specify the component to start by name (the fully-qualified class name). You'll typically use an explicit intent to start a component in your own app, because you know the class name of the activity or service you want to start. For example, start a new activity in response to a user action or start a service to download a file in the background.
Explicitly starting an Activity

Intent intent = newIntent (this, SecondActivity.class);

startActivity(intent); 

Here SecondActivity is the name of the target activity that you want to start.


Implicit intents :- do not name a specific component, but instead declare a general action to perform, which allows a component from another app to handle it. For example, if you want to show the user a location on a map, you can use an implicit intent to request that another capable app show a specified location on a map.

When you create an explicit intent to start an activity or service, the system immediately starts the app component specified in the Intent object.

Implicitly starting an Activity

If you want to view a web page with the specified URL then you can use this procedure.

Intent i = newIntent(android.content.Intent.ACTION_VIEW,Uri.parse(“http://www.google.com”));

startActivity(i); 

 

 


Figure 1. Illustration of how an implicit intent is delivered through the system to start another activity: [1] Activity A creates an Intent with an action description and passes it to startActivity(). [2] The Android System searches all apps for an intent filter that matches the intent. When a match is found, [3] the system starts the matching activity (Activity B) by invoking its onCreate() method and passing it the Intent.
When you create an implicit intent, the Android system finds the appropriate component to start by comparing the contents of the intent to the intent filters declared in the manifest file of other apps on the device. If the intent matches an intent filter, the system starts that component and delivers it the Intent object. If multiple intent filters are compatible, the system displays a dialog so the user can pick which app to use.
An intent filter is an expression in an app's manifest file that specifies the type of intents that the component would like to receive. For instance, by declaring an intent filter for an activity, you make it possible for other apps to directly start your activity with a certain kind of intent. Likewise, if you do not declare any intent filters for an activity, then it can be started only with an explicit intent.


Intent Filters

If an Intents is send to the Android system, it will determine suitable applications for this Intents. If several components have been registered for this type of Intents, Android offers the user the choice to open one of them.
This determination is based on Intent Filters. An Intent Filters specifies the types of Intent that an activity, service, or Broadcast Receiver can respond to. An Intent Filter declares the capabilities of a component. It specifies what an activity or service can do and what types of broadcasts a Receiver can handle. It allows the corresponding component to receive Intents of the declared type. Intent Filters are typically defined via the AndroidManifest.xml file. For Broadcast Receiver it is also possible to define them in coding. An Intent Filters is defined by its category, action and data filters. It can also contain additional metadata.
If a component does not define an Intent filter, it can only be called by explicit Intents.
Following are 2 ways to define a filter

1.Manifest file

If you define the intent filter in the manifest, your application does not have to be running to react to the intents defined in it’s filter. Android registers the filter when your application gets installed.

2.BroadCast Receiver

If you want your broadcast receiver to receive the intent only when your application is running. Then you should define your intent filter during run time. 

Building an Intent

An Intent object carries information that the Android system uses to determine which component to start (such as the exact component name or component category that should receive the intent), plus information that the recipient component uses in order to properly perform the action (such as the action to take and the data to act upon).
The primary information contained in an Intent is the following:
Component name
 
The name of the component to start. This is optional, but it's the critical piece of information that makes an intent explicit, meaning that the intent should be delivered only to the app component defined by the component name. Without a component name, the intent is implicit and the system decides which component should receive the intent based on the other intent information (such as the action, data, and category—described below). So if you need to start a specific component in your app, you should specify the component name.
Action
 
A string that specifies the generic action to perform (such as view or pick). In the case of a broadcast intent, this is the action that took place and is being reported. The action largely determines how the rest of the intent is structured—particularly what is contained in the data and extras.
You can specify your own actions for use by intents within your app (or for use by other apps to invoke components in your app), but you should usually use action constants defined by the Intent class or other framework classes. Here are some common actions for starting an activity:
ACTION_VIEW
Use this action in an intent with startActivity() when you have some information that an activity can show to the user, such as a photo to view in a gallery app, or an address to view in a map app.
ACTION_SEND
Also known as the "share" intent, you should use this in an intent with startActivity() when you have some data that the user can share through another app, such as an email app or social sharing app.
See the Intent class reference for more constants that define generic actions. Other actions are defined elsewhere in the Android framework, such as in Settings for actions that open specific screens in the system's Settings app.
You can specify the action for an intent with setAction() or with an Intent constructor.
If you define your own actions, be sure to include your app's package name as a prefix.
Data
 
The URI (a Uri object) that references the data to be acted on and/or the MIME type of that data. The type of data supplied is generally dictated by the intent's action. For example, if the action is ACTION_EDIT, the data should contain the URI of the document to edit. When creating an intent, it's often important to specify the type of data (its MIME type) in addition to its URI. For example, an activity that's able to display images probably won't be able to play an audio file, even though the URI formats could be similar. So specifying the MIME type of your data helps the Android system find the best component to receive your intent. However, the MIME type can sometimes be inferred from the URI—particularly when the data is a content: URI, which indicates the data is located on the device and controlled by a ContentProvider, which makes the data MIME type visible to the system.
To set only the data URI, call setData(). To set only the MIME type, call setType(). If necessary, you can set both explicitly with setDataAndType().
Caution: If you want to set both the URI and MIME type, do not call setData() and setType() because they each nullify the value of the other. Always use setDataAndType() to set both URI and MIME type.
Category
 
A string containing additional information about the kind of component that should handle the intent. Any number of category descriptions can be placed in an intent, but most intents do not require a category. Here are some common categories:
CATEGORY_BROWSABLE
The target activity allows itself to be started by a web browser to display data referenced by a link—such as an image or an e-mail message.
CATEGORY_LAUNCHER
The activity is the initial activity of a task and is listed in the system's application launcher.
See the Intent class description for the full list of categories.
You can specify a category with addCategory().
These properties listed above (component name, action, data, and category) represent the defining characteristics of an intent. By reading these properties, the Android system is able to resolve which app component it should start.
However, an intent can carry additional information that does not affect how it is resolved to an app component. An intent can also supply:
Extras
 
Key-value pairs that carry additional information required to accomplish the requested action. Just as some actions use particular kinds of data URIs, some actions also use particular extras. You can add extra data with various putExtra() methods, each accepting two parameters: the key name and the value. You can also create a Bundle object with all the extra data, then insert the Bundle in the Intent with putExtras().
For example, when creating an intent to send an email with ACTION_SEND, you can specify the "to" recipient with the EXTRA_EMAIL key, and specify the "subject" with the EXTRA_SUBJECT key.
The Intent class specifies many EXTRA_* constants for standardized data types. If you need to declare your own extra keys (for intents that your app receives), be sure to include your app's package name as a prefix.

Flags
 
Flags defined in the Intent class that function as metadata for the intent. The flags may instruct the Android system how to launch an activity (for example, which task the activity should belong to) and how to treat it after it's launched (for example, whether it belongs in the list of recent activities). For more information, see the setFlags() method.

 

 





Thursday 15 January 2015

Animation

Animations can add subtle visual cues that notify users about what's going on in your app and improve their mental model of your app's interface. Animations are especially useful when the screen changes state, such as when content loads or new actions become available. Animations can also add a polished look to your app, which gives your app a higher quality feel.
 package com.example.vanimation;

  import android.app.Activity;
  import android.content.Intent;
  import android.os.Bundle;
  import android.view.View;
  import android.view.View.OnClickListener;
  import android.widget.Button;

  public class FirstActivity extends Activity
  {
@Override
protected void onCreate( Bundle savedInstanceState )
{
    super.onCreate( savedInstanceState );
    setContentView( R.layout.activity_first );
    ((Button)findViewById( R.id.NextButton )).setOnClickListener( new OnClickListener()
    {
        @Override
        public void onClick( View v )
        {
            //startActivity( new Intent( FirstActivity.this, SecondActivity.class ) );
            Intent intent = new Intent(FirstActivity.this, SecondActivity.class);
            startActivityForResult(intent, 0);
            overridePendingTransition( R.anim.slide_in_left, R.anim.slide_out_left );
        }
    });
}
}