Android Intents - iba-s12-cse450

evasiveabstractedΚινητά – Ασύρματες Τεχνολογίες

14 Δεκ 2013 (πριν από 3 χρόνια και 7 μήνες)

758 εμφανίσεις

Android Intents

Nasrullah

Using the application context

You use the application context to access settings and
resources shared across multiple activity instances.

You can retrieve the application context for the
current process by using the
getApplicationContext
() method, like this:

Context
context

=
getApplicationContext
();

Retreiving

the
applicatio

resources

String greeting =
getResources
().
getString
(
R.string.
hello
);

Launching the activity

There are a number of ways to launch an activity, including
the following:

1.
.
Designating a launch activity in the manifest file

2.
. Launching an activity using the application context

3.
. Launching a child activity from a parent activity for a
result

Launch activity in the
manifestfile


Each Android application must designate a
default activity within the
Androidmanifest

file.

Launching Activity using Application
Context


The most common way to launch an activity is to
use the
startActivity
() method

of the application context. This method takes one
parameter, called an Intent



The following code calls the
startActivity
() method
with an explicit intent:


startActivity
(new Intent(
getApplicationContext
(),
MenuActivity.class
));

This

intent

requests

the

launch

of

the

target

activity,

named

MenuActivity
,

by

its

class
.

This

class

must

be

implemented

elsewhere

within

the

package
.

Because

the

MenuActivity

class

is

defined

within

this

application’s

package,

it

must

be

registered

as

an

activity

within

the

Android

manifest

file
.


Intent to launch the web browser with
specific
url

Uri address =
Uri.
parse
(“http://www.iba.edu.pk”);


Intent surf = new Intent(
Intent.
ACTION_VIEW
, address);


startActivity
(surf);

This

example

shows

an

intent

that

has

been

created

with

an

action

and

some

data
.
The

action,

in

this

case,

is

to

view

something
.

The

data

is

a

uniform

resource

identifier

(URI),

which

identifies

the

location

of

the

resource

to

view
.
For

this

example,

the

browser’s

activity

then

starts

and

comes

into

foreground,

causing

the

original

calling

activity

to

pause

in

the

background
.

When

the

user

finishes

with

the

browser

and

clicks

the

Back

button,

the

original

activity

resumes
.

Applications

may

also

create

their

own

intent

types

and

allow

other

applications

to

call

them,

which

makes

it

possible

to

develop

tightly

integrated

application

suites
.

Launch an activity for a result


Sometimes

you

want

to

launch

an

activity,

have

it

determine

something

such

as

a

user’s

choice,

and

then

return

that

information

to

the

calling

activity
.

When

an

activity

needs

a

result

,

it

can

be

launched

using

the

Activity
.
startActivityForResult
()

method
.

The

result

is

returned

in

the

Intent

parameter

of

the

calling

activity’s

onActivityResult
()

method
.

We

talk

more

about

how

to

pass

data

using

an

Intent

parameter

in

a

moment
.

Intents


Intents are asynchronous messages which
allow android components to request
functionality from other components of the
android components.


An activity send an intent to another system
which starts an other activity



Intents are the instances of


Android.content.Instance

Explicity

Intent


Explictiy

intents explicitly name the component
which should be called by the android
system,by

using the java class as identifier.


Intent
i

= new Intent(this,
ActivityTwo.class
);




i.putExtra
("Value1", "This value one for
ActivityTwo

");



i.putExtra
("Value2", "This value two
ActivityTwo
");


If this intent is correctly send to the android
system,it

will start the associated class.

Implicti

Intents


Implicit Intents do not specify the Java class
which should be called. They specify the
action which should be performed and
optionally an URI which should be used for
this action.


Gridlayout


Android 4.0 (Ice Cream Sandwich) introduced
a new type of layouts: the
Gridlayout
.

Gridlayout

is like the
<Table>

tag in
HTML
.
child widgets are arranged in
Cells

made of
Rows

and
Columns
.


Grid layout is a
ViewGroup

that can be used in
constructing dashboard activities like that one
in the Google Plus application:


Final in java


In Java,
final
keyword is applied in various
context. The
final

keyword is a modifier means
the
final

class can't be extended, a variable
can't be modified, and also a method can't be
override