Beruflich Dokumente
Kultur Dokumente
1
Toast class
• Toast class is used to show notification for a
particular interval of time. After sometime it
disappears. It doesn't block the user
interaction.
• Constants of Toast class
• There are only 2 constants of Toast class which
are given below.
2
• Methods of Toast class
• The widely used methods of Toast class are
given below.
3
Android Toast Example
Toast toast=Toast.makeText(getApplicationContext(),
"Hello Javatpoint",Toast.LENGTH_SHORT);
toast.setMargin(50,50);
toast.show();
OR
Toast.makeText(getApplicationContext(),
"Hello Javatpoint",Toast.LENGTH_SHORT).show();
4
Working with Intents
5
Intent
(a simple message objects which is used to communicate from one activity to
another)
An intent is an abstract description of an operation to be performed
• Intent Classification.
• Explicit intent : This kind of intent will define the
target component (Activity, Service etc) directly.
So only the specified target component will be
invoked.
• Implicit Intent : This kind of Intent will not specify
the component ( Activity, Service etc ) directly. It
only specify the action and category information.
Then android OS will filter out and start the
component which can response to the action and
category.
7
• Explicit Intent Example.
• There are two Activity in below example. When
you click the button in the first activity, it will use
an explicit Intent to tell android OS to start the
second Activity immediately. And transfer some
string data to the second activity also.
• When you click the bottom back menu while the
second activity is active, the second activity will
be closed and the first activity will be shown
again.
8
Explicit Intent
(the Intent in which you explicitly define the component that needs to be called by
Android System)
An explicit intent is one that you use to launch a specific app component, such as a particular
activity or service in your app.
Syntax :
Intent openNewActivity = new Intent (getApplicationContext(), SecondActivity.class);
9
Implicit Intent
(the intent where instead of defining the exact components, you define the action
you want to perform)
•An implicit intent specifies an action that can invoke any app on the device able to
perform the action.
•Using an implicit intent is useful when your app cannot perform the action, but
other apps probably can and you'd like the user to pick which app to use.
Syntax :
10
Built-in Standard Intent Actions
List of standard actions that Intents can use for launching activities (usually
through startActivity(Intent).
ACTION_MAIN ACTION_SENDTO
ACTION_VIEW ACTION_ANSWER
ACTION_ATTACH_DATA ACTION_INSERT
ACTION_EDIT ACTION_DELETE
ACTION_PICK ACTION_RUN
ACTION_CHOOSER ACTION_SYNC
ACTION_GET_CONTENT ACTION_PICK_ACTIVITY
ACTION_DIAL ACTION_SEARCH
ACTION_CALL ACTION_WEB_SEARCH
ACTION_SEND ACTION_FACTORY_TEST
11
12
13
Data Passing
Bundle object is used to pass data between activities. You can still use
putExtra method to associate a bundle with an Intent.
14
Directly using putExtra
This data can be of different types : string, char, Boolean, Bundle etc.
This data gets set as key value pair which you can retrieve in the called
activity.
The code below describes as to how we collect data into the Intent object
Intent intentObject = getIntent();
String userName = intentObject.getStringExtra ("UserName","");
boolean isRegistered = intentObject.getBooleanExtra ("isRegistered", true);
15