You are on page 1of 3

PRACTICAL: 5

AIM: Passing data to another activity (Intent).


Examples of Implicit Intent.
1. Phone call
2. Open Browser

Activity_main.xml
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >

<Button android:id="@+id/start_browser"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="start_browser"/>

<Button android:id="@+id/start_phone"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="start_phone" />

</LinearLayout>

MOBILE COMPUTING AND WIRELESS COMMUNICATION 22 | 1 4 0 1 1 3 1 0 7 0 0 5


MainActivity.java
package com.example.intentdemo;

import android.os.Bundle;
import android.app.Activity;
import android.view.Menu;
import android.net.Uri;
import android.content.Intent;
import android.view.View;
import android.widget.Button;

public class MainActivity extends Activity {

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

Button startBrowser = (Button) findViewById(R.id.start_browser);


startBrowser.setOnClickListener(new View.OnClickListener() {
public void onClick(View view)
{
Intent i = new Intent(android.content.Intent.ACTION_VIEW,
Uri.parse("http://www.example.com"));
startActivity(i);
} });

Button startPhone = (Button) findViewById(R.id.start_phone);


startPhone.setOnClickListener(new View.OnClickListener() {
public void onClick(View view)
{
Intent i = new Intent(android.content.Intent.ACTION_VIEW,
Uri.parse("tel:9876543210"));
startActivity(i);
} }); }

@Override
public boolean onCreateOptionsMenu(Menu menu)
{
getMenuInflater().inflate(R.menu.activity_main, menu);
return true;
}
}

MOBILE COMPUTING AND WIRELESS COMMUNICATION 23 | 1 4 0 1 1 3 1 0 7 0 0 5


Output:

MOBILE COMPUTING AND WIRELESS COMMUNICATION 24 | 1 4 0 1 1 3 1 0 7 0 0 5

You might also like