Skip to content

Using Android Intents Tutorial

Intents are just what they sound like, a way to declare to the Android Framework what you intend to do. This can be starting a specific activity, or it can be just asking Android to find some program that can perform an action (whether or not you know what programs are available). We can also go in the other direction, and determine what actions are available to us for a particular piece of content. We are going to cover each of these topics in this article.

In this article I showed you how to open a specific activity using the startActivity method and an Intent that specifies a class. This is just the tip of the iceberg when it comes to using intents.

Here is the basic activity I am going to be using for the rest of this article. At this point, it is just a ListActivity which is going to reference the different examples we are going to see.

package com.learnandroid.intents;
 
import android.app.ListActivity;
import android.os.Bundle;
import android.widget.ArrayAdapter;
import android.widget.ListAdapter;
 
public class UsingIntentsActivity extends ListActivity {
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        ListAdapter adapter = createAdapter();
        setListAdapter(adapter);
    }
 
    protected ListAdapter createAdapter()
    {
    	String[] listValues = new String[] {
    			"The Activity You Know",
    			"The URI You Know",
    			"When You Just Don't Know"
    	};
 
    	// Create a simple array adapter (of type string) with the test values
    	ListAdapter adapter = new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1
    			, listValues);
 
    	return adapter;
    }
}

Next: The Activity You Know

{ 2 } Comments

  1. shub | May 30, 2012 at 5:07 pm | Permalink

    i am new to android can you please explain what is onclicklistner (not what is does) and why we use View.onclicklistner and what is view there

  2. krishna | August 10, 2012 at 2:19 am | Permalink

    very useful, thaks..

Post a Comment

Your email is never published nor shared. Required fields are marked *