Sie sind auf Seite 1von 30

#

WWW.PENTALOG.COM
Curs 7

Activities

Constraint Layouts

OnClickListener

SharedPreferences

WWW.PENTALOG.COM
Constraint Layout

What is ?
Why do we need them?

How do I get Constraint Layout?


-->A ConstraintLayout is a ViewGroup which allows you to position
and size widgets in a flexible way.
--> ConstraintLayout allows you to create large and complex layouts
with a flat view hierarchy (no nested view groups). It's similar to
RelativeLayout in that all views are laid out according to relationships
between sibling views and the parent layout. AKA SPEED!!!

WWW.PENTALOG.COM
Should look like this !!!

Design View || Blueprint View


#

WWW.PENTALOG.COM
Dive in !

WWW.PENTALOG.COM
#

WWW.PENTALOG.COM
#

WWW.PENTALOG.COM
#

WWW.PENTALOG.COM
#

WWW.PENTALOG.COM
#

WWW.PENTALOG.COM
Activities

If you have worked with C, C++ or Java programming language then you must
have seen that your program starts from main() function. Very similar way,
Android system initiates its program with in an Activity starting with a call on
onCreate() callback method. There is a sequence of callback methods that start
up an activity and a sequence of callback methods that tear down an activity..

WWW.PENTALOG.COM
#

WWW.PENTALOG.COM
Activities

WWW.PENTALOG.COM
#

WWW.PENTALOG.COM
Activities

Explicit intents specify the component to start by name (the fully-qualified


class name). You'll typically use an explicit intent to start a component in
your own app, because you know the class name of the activity or service
you want to start. For example, you can start a new activity in response to a
user action or start a service to download a file in the background.
Implicit intents do not name a specific component, but instead declare a
general action to perform, which allows a component from another app to
handle it. For example, if you want to show the user a location on a map,
you can use an implicit intent to request that another capable app show a
specified location on a map.

WWW.PENTALOG.COM
Activities

Explicit intent
An explicit intent is one that you use to launch a specific app component, such
as a particular activity or service in your app. To create an explicit intent, define
the component name for the Intent objectall other intent properties are
optional.

WWW.PENTALOG.COM
Implicit Intents

WWW.PENTALOG.COM
Activities

Declare intent filters


Intent filters are a very powerful feature of the Android platform. They provide
the ability to launch an activity based not only on an explicit request, but also an
implicit one. For example, an explicit request might tell the system to Start the
Send Email activity in the Gmail app". By contrast, an implicit request tells the
system to Start a Send Email screen in any activity that can do the job." When
the system UI asks a user which app to use in performing a task, thats an intent
filter at work.
You can take advantage of this feature by declaring an <intent-filter> attribute
in the <activity> element. The definition of this element includes an <action>
element and, optionally, a <category> element and/or a <data> element. These
elements combine to specify the type of intent to which your activity can
respond.

WWW.PENTALOG.COM
Activities

In this example, the <action> element specifies that this activity sends data.
Declaring the <category> element as DEFAULT enables the activity to receive
launch requests. The <data> element specifies the type of data that this activity
can send.

WWW.PENTALOG.COM
Activities

If you intend for your app to be self-contained and not allow other apps to
activate its activities, you don't need any other intent filters. Activities that you
don't want to make available to other applications should have no intent filters,
and you can start them yourself using explicit intents.

WWW.PENTALOG.COM
OnClickListener

WWW.PENTALOG.COM
OnClickListener

WWW.PENTALOG.COM
OnClickListener

WWW.PENTALOG.COM
OnClickListener

WWW.PENTALOG.COM
Shared Preferences

Android provides many ways of storing data of an application. One of this way is
called Shared Preferences. Shared Preferences allow you to save and retrieve
data in the form of key,value pair.
In order to use shared preferences, you have to call a method
getSharedPreferences() that returns a SharedPreference instance pointing to
the file that contains the values of preferences.

WWW.PENTALOG.COM
Shared Preferences

WWW.PENTALOG.COM
Shared Preferences

WWW.PENTALOG.COM
Shared Preferences

WWW.PENTALOG.COM
Shared Preferences

WWW.PENTALOG.COM
Shared Preferences

WWW.PENTALOG.COM

Das könnte Ihnen auch gefallen