Wednesday, 6 May 2015

Lesson 10 Using Android Intents Tutorial ---- 1

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;
    }
}

No comments:

Post a Comment