Cs E - 76: Building Mobile Applica8Ons: Intents, Menus, and Sharedpreferences
Cs E - 76: Building Mobile Applica8Ons: Intents, Menus, and Sharedpreferences
Ac8vity
Results
startAc8vityForResult(intent)
allows
us
to
return
data
to
the
calling
Ac8vity
onAc8vityResult(int
requestCode,
int
resultCode,
Intent
data);
requestCode:
unique
integer
to
determine
what
Ac8vity
returned
resultCode:
RESULT_OK,
RESULT_CANCELED
data:
Intent
to
receive
addi8onal
data
nish() pops from stack and sends control back to previous Ac8vity
Bundles
Bundle
objects
store
key
and
value
pairs
via
the
put<type>
methods
and
get<type>
methods
Basic
data
types:
Boolean,
Byte,
Char,
Double,
Float,
Int,
Long,
etc.
Non-primi8ves:
String,
Serializable,
Arrays
Bundles
(contd)
intent.putExtras(Bundle
bundle);
Associate
a
bundle
with
an
intent
getIntent().getExtras();
Get
bundle
associated
with
an
intent
Menus
Described
in
XML,
stored
in
res/menu
<menu>
has
many
<item>
children
Accessed
like
other
resources
(R.menu.<lename>)
Menus
(contd)
onCreateOp8onsMenu(Menu
menu)
User
presses
menu
bunon
on
device
Menus
onOp8onsItemSelected(MenuItem
item)
User
selects
an
op8on
from
the
menu
coming
from
the
menu
bunon
onContextItemSelected(MenuItem
item)
User
selected
an
op8on
from
a
context
menu
Item.getItemId()
Gets
ID
of
selected
item
Submenus
<item>
elements
can
also
contain
other
<menu>
items!
When
<item>
is
selected,
a
submenu
will
open
as
a
context
menu
SharedPreferences
Lightweight
key-value
pair
storage
General
framework
that
allows
you
to
save
and
retrieve
persistent
key-value
pairs
of
primi8ve
data
types.
Use
it
to
save
any
primi8ve
data:
booleans,
oats,
ints,
longs,
and
strings.
Persist
amongst
user
sessions