Android Application Development
Android Application Development
Android
• Android Application
Architecture
SSDN
21-07-2018 2
What year was
Android
founded?
SSDN
21-07-2018 3
WHY
ANDROID ?
SSDN
21-07-2018 4
INTRODUCTION TO ANDROID
SSDN
21-07-2018 5
HISTORY OF ANDROID
SSDN
21-07-2018 6
ANDROID 1.0 - API LEVEL 1
SSDN
21-07-2018 7
ANDROID 1.1 - API LEVEL 2
SSDN
21-07-2018 8
ANDROID 1.5- API LEVEL 3
(CUPCAKE)
SSDN
21-07-2018 9
ANDROID 1.6- API LEVEL 4
(DONUT)
SSDN
21-07-2018 10
ANDROID 2.2- API LEVEL 8
(FROYO)
SSDN
21-07-2018 11
ANDROID 2.3-2.3.3
API LEVEL 9-10
(GINGERBREAD)
SSDN
21-07-2018 12
ANDROID 3.0,3.1,3.2
API LEVEL 11,12,13
(HONEYCOMB)
SSDN
21-07-2018 13
ANDROID 4.0,4.0.3
API LEVEL 14,15
(ICE CREAM SANDWICH)
SSDN
21-07-2018 14
ANDROID 4.1,4.3
API LEVEL 16,18
(JELLY BEAN)
SSDN
21-07-2018 15
ANDROID 4.4,4.4.w
API LEVEL 19,20
(JELLY BEAN)
SSDN
21-07-2018 16
ANDROID 5.0,5.1
API LEVEL 21,22
(KITKAT)
SSDN
21-07-2018 17
ANDROID 6.0
API LEVEL 23
(MARSHMALLOW)
SSDN
21-07-2018 18
ANDROID 7.0
API LEVEL 24
(NOUGAT)
SSDN
21-07-2018 19
ANDROID 8.0,8.1
API LEVEL 26
(OREO)
SSDN
21-07-2018 20
What is an
Application?
SSDN
21-07-2018 21
SSDN
21-07-2018 22
• Android consists of a kernel based on Linux kernel
with middleware, libraries and APIs written in C
• Application software running on an application
• Framework which includes Java-compatible libraries
based on Apache Harmony.
• Android uses the Dalvik virtual machine with just-in-
time compilation to run Dalvik 'dex-code‘
SSDN
21-07-2018 23
• Android uses Linux for its device drivers, memory
management, process management, and networking.
• Android native libraries written in C/C++ internally,
but you’ll be calling them through Java interfaces.
• Dalvik Virtual Machine. Runs dex files, which are
coverted at compile time from standard class and jar
files.
SSDN
21-07-2018 24
What are OOPS
concepts of
JAVA ?
SSDN
21-07-2018 25
Application components are the essential building
blocks of an Android application.
Each component is a different point through which
the system can enter your application.
Four main types of application components:
Activities
Services
Content providers
Broadcast receivers
SSDN
21-07-2018 26
Activities
An activity represents a single screen with a user
interface.
Services
A service is a component that runs in the background
to perform long-running operations or to perform work
for remote processes. A service does not provide a user
interface, or a picture was captured. Applications can
also initiate broadcasts.
SSDN
21-07-2018 27
Content providers
A content provider manages a shared set of application
data. You can store the data in the file system, an SQLite
database, on the web, or any other persistent storage
ocation your application can access. Through the content
provider, other applications can query or even modify the
data (if the content provider allows it).
Broadcast receivers
A broadcast receiver is a component that responds to
system-wide broadcast announcements. Many broadcasts
originate from the system—for example, a broadcast
announcing that the screen has turned off, the battery is
low
SSDN
21-07-2018 28
Hardware Reuirements
Min 4GB RAM
i3 Processor
Software Requirement
JDK
Android Studio
SSDN
21-07-2018 29
An Integrated Development Environment (IDE) is an
all-in-one solution that allows an app developer to
perform the software development cycle repeatedly
and quickly.
FOR ANDROID-
ANDROID STUDIO - Best
SSDN
21-07-2018 30
• Contains your Activity file, which is
stored at s
src/your/package/ActivityName.java
.
• All other source code files (such as
.java go here as well.
SSDN
21-07-2018 31
Contains the Java files generated by
ADT, such as your R.java file
SSDN
21-07-2018 32
Contains application resources, such as
drawable files, layout files and string
values
SSDN
21-07-2018 33
For XML files that are compiled
into animation objects
SSDN
21-07-2018 34
For XML files that describe colors
SSDN
21-07-2018 35
For bitmap files (PNG, JPEG, or GIF),
9-Patch image files, and XML files
that
describe Drawable shapes
SSDN
21-07-2018 36
XML files that are compiled into
screen layouts (or part of a screen)
SSDN
21-07-2018 37
These files are processed by aapt
and must be referenced from the
application using a resource
identifier in the R class. For
example, this is a good place for
media,
such as MP3 or Ogg files.
SSDN
21-07-2018 38
For XML files that are compiled into
many kinds of resource.
SSDN
21-07-2018 39
The control file that describes the
nature of the application and each
of its components..
SSDN
21-07-2018 40
BUILD PROCESS
SSDN
21-07-2018 41
Android is a multi-process system, in which each
application (and parts of the system) runs in its own
process
User and group IDs are assigned to applications.
Additional finer-grained security features are
provided through a "permission" mechanism.
SSDN
21-07-2018 42
• Android Widgets
• Layouts
• Shared Preferences
• Intent
SSDN
21-07-2018 43
What do we
need to create
a Login FORM?
SSDN
21-07-2018 44
ANDROID LAYOUTS
SSDN
21-07-2018 45
DECLARING LAYOUTS
SSDN
21-07-2018 47
LAYOUTS – Reference in JAVA Code
wrap_content
tells your view to size itself to the dimensions required
by its content
match_parent
tells your view to become as big as its parent view
group will allow.
<Button android:id="@+id/my_button"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/my_button_text"/>
SSDN
21-07-2018 49
LAYOUT TYPES
LinearLayout
RelativeLayout
TableLayout
SSDN
21-07-2018 50
LINEAR LAYOUT
Textview
Edittext
Button
Checkbox
RadioButton
ImageView
ImageButton
RadioButton
ToggleButton
SSDN
21-07-2018 56
IMAGEVIEW
SSDN
21-07-2018 57
IMAGEVIEW
<ImageView android:id="@+id/imageView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/android" />
<Button android:id="@+id/btnChangeImage"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Change Image" />
SSDN
21-07-2018 58
IMAGEVIEW
SSDN
21-07-2018 59
IMAGEBUTTON
ImageButton = (ImageButton)
findViewById(R.id.imageButton1);
imageButton.setOnClickListener(new
OnClickListener() { @Override public void
onClick(View arg0) {
Toast.makeText(MyAndroidAppActivity.this,
"ImageButton is clicked!",
Toast.LENGTH_SHORT).show(); } });
SSDN
21-07-2018 60
IMAGEBUTTON
<ImageButton
android:id="@+id/imageButton1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/android_button" />
SSDN
21-07-2018 61
IMAGEBUTTON
SSDN
21-07-2018 62
BUTTON
SSDN
21-07-2018 63
BUTTON
buttonSum.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
String value1=edittext1.getText().toString();
String value2=edittext2.getText().toString();
int a=Integer.parseInt(value1);
int b=Integer.parseInt(value2);
int sum=a+b;
Toast.makeText(getApplicationContext(),String.valueOf(sum), Toast.LENGTH_
LONG).show();
}
});
SSDN
21-07-2018 64
CHECKBOX
SSDN
21-07-2018 65
CHECKBOX
pizza=(CheckBox)findViewById(R.id.checkBox);
coffe=(CheckBox)findViewById(R.id.checkBox2);
burger=(CheckBox)findViewById(R.id.checkBox3);
buttonOrder=(Button)findViewById(R.id.button);
@Override
public void onClick(View view) {
int totalamount=0;
StringBuilder result=new StringBuilder();
result.append("Selected Items:");
if(pizza.isChecked()){
result.append("\nPizza 100Rs");
totalamount+=100;
}
SSDN
21-07-2018 66
CHECKBOX
if(coffe.isChecked()){
result.append("\nCoffe 50Rs");
totalamount+=50;
}
if(burger.isChecked()){
result.append("\nBurger 120Rs");
totalamount+=120;
}
result.append("\nTotal: "+totalamount+"Rs");
//Displaying the message on the toast
Toast.makeText(getApplicationContext(), result.toString(), Toast.LENGTH_LONG).sh
ow();
}
});
SSDN
21-07-2018 67
CHECKBOX
<CheckBox
android:id="@+id/checkBox3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="144dp"
android:layout_marginTop="28dp"
android:text="Burger"
/>
SSDN
21-07-2018 68
RADIOBUTTON
SSDN
21-07-2018 69
RADIOBUTTON
SSDN
21-07-2018 70
RADIOBUTTON
SSDN
21-07-2018 71
CUSTOM TOAST
LayoutInflater li = getLayoutInflater();
//Getting the View object as defined in the customtoast.xml file
View layout = li.inflate(R.layout.customtoast,(ViewGroup) findViewById(R.
id.custom_toast_layout));
SSDN
21-07-2018 72
CUSTOM TOAST
activity_main.xml
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Hello World!"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent" />
SSDN
21-07-2018 73
CUSTOM TOAST
custom.xml
<ImageView
android:id="@+id/custom_toast_image"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:contentDescription="Hello world"
android:src="@drawable/jtp_logo"/>
<TextView
android:id="@+id/custom_toast_message"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:contentDescription="To"
android:text=“SSDN custom Toast" />
SSDN
21-07-2018 74
• Intent in Android
• Adapters
• SharedPreferences
SSDN
21-07-2018 75
INTENT IN ANDROID
SSDN
21-07-2018 76
Explicit Intents
Implicit Intents
SSDN
21-07-2018 77
Used to launch a specific component like activity or a
service.
In this case, android system directly forwards this intent to
that specific component.
It is faster.
Always use explicit intents if you know the specific activity
or service that performs intended thing
SSDN
21-07-2018 78
Specifies an action that can invoke an app on the device
that can perform the action.
Useful when your app can not perform the action but
other apps do and you let user to pick up the app.
Its possible that there may not be any app that handles
the implicit intent.
Intent intent=new Intent(Intent.ACTION_VIEW);
intent.setData(Uri.parse("http://www.google.com"));
startActivity(intent);
SSDN
21-07-2018 79
FirstActivity
String value="Hello world";
Intent i = new Intent(FirstActivity.this,
SecondActivity.class);
i.putExtra("key",value);
startActivity(i);
SSDN
21-07-2018 80
SecondActivity
Bundle extras = getIntent().getExtras();
if (extras != null) {
String value = extras.getString("key");
SSDN
21-07-2018 81
Android provides many ways of storing data of an
application. Shared Preferences allow you to save and
retrieve data in the form of key,value pair.
SSDN
21-07-2018 82
Preferences in Android are used to keep track of application
and user preferences.
In any application, there are default preferences that can
accessed through the
PreferenceManager instance and its related method
getDefaultSharedPreferences(Context)
With the SharedPreference instance one can retrieve the int
value of the any preference with the getInt(String key, int
defVal).
4. In our case, we can modify the SharedPreference instance in
our case using the edit() and use the putInt(String key, int
newVal)
SSDN
21-07-2018 83
SSDN
21-07-2018 84
• Adapters
SSDN
21-07-2018 85
ADAPTERS IN ANDROID
SSDN
21-07-2018 86
ADAPTERS CLASS
SSDN
21-07-2018 88
FILLING LAYOUT WITH DATA
SSDN
21-07-2018 89
HANDLING USER SELECTIONS
SSDN
21-07-2018 90
HANDLING USER SELECTIONS
SSDN
21-07-2018 91
LISTVIEW CLASS
SSDN
21-07-2018 92
LISTVIEW CLASS
SSDN
21-07-2018 93
LISTVIEW CLASS
STEP 1
Create a new project Listexample and activity Main Activity.
Here we will create a ListView in LinearLayout. Below is the
code of activity_main.xml or content_main.xml:
SSDN
21-07-2018 94
LISTVIEW CLASS
STEP 1
<LinearLayout xmlns:android="http://schemas.android.com/apk/res
/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<ListView
android:id="@+id/simpleListView"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
andrandroid:dividerHeight="1dp" />
</LinearLayout>
SSDN
21-07-2018 95
LISTVIEW CLASS
STEP2
Create a new activity name Listview and below is the code of
activity_listview.xml
SSDN
21-07-2018 96
LISTVIEW CLASS
STEP2
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/androi
d"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<TextView
android:id="@+id/textView"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:padding=“10dp"
android:textColor=“#453647" />
</LinearLayout>
SSDN
21-07-2018 97
LISTVIEW CLASS
STEP3
Now in this final step we will use ArrayAdapter to display the
country names in UI. Below is the code of MainActivity.java
SSDN
21-07-2018 98
LISTVIEW CLASS
STEP3
public class MainActivity extends Activity
{
// Array of strings...
ListView simpleList;
String countryList[] = {"India", "China", "australia", "Portugle", "America", "New
Zealand"};
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
simpleList = (ListView)findViewById(R.id.simpleListView);
ArrayAdapter<String> arrayAdapter = new ArrayAdapter<String>(this, R.layou
t.activity_listview, R.id.textView, countryList);
simpleList.setAdapter(arrayAdapter);
}
}
Run your App……..YoooYooo
SSDN
21-07-2018 99
LISTVIEW CLASS – BASE ADAPTER
SSDN
21-07-2018 100
LISTVIEW CLASS
STEP1
Create a new projec Listebasexample and activity Main
Activity. Here we will create a ListView in LinearLayout. Below
is the code of activity_main.xml :
SSDN
21-07-2018 101
LISTVIEW CLASS
STEP1
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<ListView android:id="@+id/simpleListView"
android:layout_width=“match_parent"
android:layout_height="wrap_content"
android:dividerHeight="1dp" />
</LinearLayout>
SSDN
21-07-2018 102
LISTVIEW CLASS
STEP2
Create a new activity name Listview and below is the code of
activity_listview.xml
SSDN
21-07-2018 103
LISTVIEW CLASS
STEP2
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent" android:layout_height="match_parent"
android:orientation="horizontal">
<ImageView android:id="@+id/icon"
android:layout_width="50dp"
android:layout_height="50dp“
android:src="@drawable/ic_launcher" />
<TextView android:id="@+id/textView“
android:layout_width="fill_parent"
android:layout_height="wrap_content“
android:layout_gravity="center"
android:padding=“10dp"
android:textColor="@color/black" />
</LinearLayout>
SSDN
21-07-2018 104
LISTVIEW CLASS
STEP3
In third step we will use custom adapter to display the country
names in UI by coding MainActivity.java. Below is the code of
MainActivity.java
SSDN
21-07-2018 105
LISTVIEW CLASS
STEP3
public class MainActivity extends Activity
{
ListView simpleList;
String imagesList[] = {"India", "China", "australia", "Portugle", "America",
"NewZealand"};
int images[] = {R.drawable.india, R.drawable.china, R.drawable.australia,
R.drawable.portugle, R.drawable.america, R.drawable.new_zealand};
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState); setContentView(R.layout.activity_main);
simpleList = (ListView) findViewById(R.id.simpleListView);
CustomAdapter customAdapter = new
CustomAdapter(getApplicationContext(), imagesList, images);
simpleList.setAdapter(customAdapter);
}
}
SSDN
21-07-2018 106
LISTVIEW CLASS
STEP4
Now create another class Custom Adapter which will extend
BaseAdapter. Below is the code of CustomAdapter.java
SSDN
21-07-2018 107
GRIDVIEW CLASS
SSDN
21-07-2018 108
GRIDVIEW CLASS
SSDN
21-07-2018 109
GRIDVIEW CLASS
STEP 1
Create a new Android project in Android Studio and fill all
the required details. In our case we have named
GridViewExample and package
com.example.gourav.GridViewExample
SSDN
21-07-2018 110
GRIDVIEW CLASS
STEP 2
Open activity_main.xml and paste the below code. In this
we have created a Grid view inside Linear Layout and also
set number of columns to 3.
SSDN
21-07-2018 111
STEP 2 GRIDVIEW CLASS
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/andr
oid" android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<GridView android:id="@+id/simpleGridView"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:footerDividersEnabled="false"
android:padding="1dp“
android:numColumns="3" />
</LinearLayout>
SSDN
21-07-2018 112
GRIDVIEW CLASS
STEP 3
Create a new XML file and paste the below code. We have
named activity_gridview.xml.
In this step we create a new XML file and add
a ImageView in it.
SSDN
21-07-2018 113
STEP 3 GRIDVIEW CLASS
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/andr
oid" android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="1dp" android:orientation="vertical">
<ImageView
android:id="@+id/icon"
android:layout_width="match_parent"
android:layout_height="120dp"
android:scaleType="fitXY"
android:layout_gravity="center_horizontal"
android:src="@drawable/logo1" />//name of image
</LinearLayout>
SSDN
21-07-2018 114
GRIDVIEW CLASS
STEP4
Now open drawable folder and save small size png images
of different logo’s and name them like logo1,logo2 and etc.
SSDN
21-07-2018 115
GRIDVIEW CLASS
SSDN
21-07-2018 116
GRIDVIEW CLASS
STEP 6
Create a new class CustomAdapter and
paste the below code.
In this step we create a CustomAdapter class
by extending BaseAdapter in it. In this step
we set the logo image’s in the grid items
SSDN
21-07-2018 117
GRIDVIEW CLASS
STEP 7
Now Create a new XML file named
activity_second and paste the below code in it.
In this step we create an XML file for our Second
Activity to display the logo image in full size.
SSDN
21-07-2018 118
GRIDVIEW CLASS
STEP 7
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
android:background="#fff"
tools:context="com.example.gourav.GridViewExample.SecondAc
tivity">
<ImageView android:id="@+id/selectedImage"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:scaleType="fitXY" />
</RelativeLayout>.
SSDN
21-07-2018 119
GRIDVIEW CLASS
STEP 8
Now Create a new Activity with name
SecondActivity.class
SSDN
21-07-2018 120
GRIDVIEW
STEP 8
CLASS
public class SecondActivity extends AppCompatActivity
{
ImageView selectedImage;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_second);
selectedImage = (ImageView)
findViewById(R.id.selectedImage);
Intent intent = getIntent();
selectedImage.setImageResource(intent.getIntExtra("
image", 0));
}}
YOYO RUN APP……………………
SSDN
21-07-2018 121
SPINNER CLASS
SSDN
21-07-2018 122
SPINNER CLASS
SSDN
21-07-2018 123
SPINNER CLASS
SSDN
21-07-2018 124
SPINNER CLASS
SSDN
21-07-2018 125
SPINNER CLASS
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/a
ndroid"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">
<Spinner
android:id="@+id/simpleSpinner"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_marginTop="100dp" />
</RelativeLayout>
SSDN
21-07-2018 126
SPINNER CLASS
SSDN
21-07-2018 127
SPINNER CLASS
OUTPUT
SSDN
21-07-2018 128
• Networking in Android
• Broadcast Receivers
• Services
• Notifications
• Web View
SSDN
21-07-2018 129
Accessing the network in Android
Permission to access the network
Check the network availability
SSDN
21-07-2018 130
Accessing the network in Android
SSDN
21-07-2018 131
Permission to access the network
SSDN
21-07-2018 132
Check the network availability
SSDN
21-07-2018 135
public class MyReceiver extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent)
{
Toast.makeText(context, "Intent Detected.",
Toast.LENGTH_LONG).show();
}}
SSDN
21-07-2018 136
<application android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" > <receiver
android:name="MyReceiver"> <intent-filter> <action
android:name="android.intent.action.BOOT_COMPLET
ED"> </action> </intent-filter> </receiver>
</application>
SSDN
21-07-2018 137
SSDN
21-07-2018 138
Creating the Broadcast Receiver.
Registering Broadcast Receiver
SSDN
21-07-2018 139
A Service is an application component that can
perform long-running operations in the background,
and it doesn't provide a user interface. Another
application component can start a service, and it
continues to run in the background even if the user
switches to another application
SSDN
21-07-2018 140
foreground service performs some operation that is
noticeable to the user. For example, an audio app
would use a foreground service to play an audio track.
Foreground services must display a Notification.
Foreground services continue running even when the
user isn't interacting with the app.
SSDN
21-07-2018 141
BackgroundA background service performs an
operation that isn't directly noticed by the user. For
example, if an app used a service to compact its
storage, that would usually be a background service.
SSDN
21-07-2018 142
Bound service is bound when an application component
binds to it by calling bindService(). A bound service offers
a client-server interface that allows components to
interact with the service, send requests, receive results,
and even do so across processes with interprocess
communication (IPC). A bound service runs only as long as
another application component is bound to it. Multiple
components can bind to the service at once, but when all
of them unbind, the service is destroyed.
SSDN
21-07-2018 143
To create a service, you must create a subclass
of Service or use one of its existing subclasses
onStartCommand()The system invokes this method by
calling startService() when another component (such
as an activity) requests that the service be started
nBind()The system invokes this method by
calling bindService() when another component wants
to bind with the service
SSDN
21-07-2018 144
onCreate()The system invokes this method to perform
one-time setup procedures when the service is initially
created (before it calls either onStartCommand()
or onBind()). If the service is already running, this method
is not called.
onDestroy()The system invokes this method when the
service is no longer used and is being destroyed. Your
service should implement this to clean up any resources
such as threads, registered listeners, or receivers. This is
the last call that the service receives.
SSDN
21-07-2018 145
A notification is a message you can display to the user
outside of your application's normal UI.
SSDN
21-07-2018 146
Step 1 - Create Notification Builder
NotificationCompat.Builder mBuilder = new
NotificationCompat.Builder(this)
SSDN
21-07-2018 147
Step 2 - Setting Notification Properties
mBuilder.setSmallIcon(R.drawable.notification_icon);
mBuilder.setContentTitle("Notification Alert, Click
Me!");
mBuilder.setContentText("Hi, This is Android
Notification Detail!");
SSDN
21-07-2018 148
Step 3 - Attach Actions
SSDN
21-07-2018 149
Step 3 - Attach Actions
SSDN
21-07-2018 150
Step 4- Issue the notification
NotificationManager mNotificationManager =
(NotificationManager)
getSystemService(Context.NOTIFICATION_SERVICE); //
notificationID allows you to update the notification later on.
mNotificationManager.notify(notificationID, mBuilder.build());
SSDN
21-07-2018 151
<WebView
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/webview“
android:layout_width="fill_parent"
android:layout_height="fill_parent"
/>
SSDN
21-07-2018 152
String url = ed1.getText().toString();
wv1.getSettings().setLoadsImagesAutomatically(true);
wv1.getSettings().setJavaScriptEnabled(true);
wv1.setScrollBarStyle(View.SCROLLBARS_INSIDE_OVERLAY);
wv1.loadUrl(url);
SSDN
21-07-2018 153
private class MyBrowser extends WebViewClient
{ @Override
public boolean shouldOverrideUrlLoading(WebView view, String
url) {
view.loadUrl(url);
return true;
}
}
SSDN
21-07-2018 154
<manifest
xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.sairamkrishna.myapplication" >
<uses-permission
android:name="android.permission.INTERNET" />
<application android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
SSDN
21-07-2018 155
• Alarm Manager
Fragment
• Navigation Drawer
• View Pager
SSDN
21-07-2018 156
By the help of Android AlarmManager in android, you
can schedule your application to run at a specific
time in the future. It works whether your phone is
running or not.
SSDN
21-07-2018 157
activity_main.xml
SSDN
21-07-2018 158
MainActivity.java
SSDN
21-07-2018 159
MyBroadcastReceiver .java
SSDN
21-07-2018 160
AndroidManifest.xml
SSDN
21-07-2018 161
AndroidManifest.xml
SSDN
21-07-2018 162
SSDN
21-07-2018 163
The navigation drawer is a UI panel that shows your app's main
navigation menu. It is hidden when not in use, but appears when
the user swipes a finger from the left edge of the screen or,
when at the top level of the app, the user touches the drawer
icon in the app bar.
SSDN
21-07-2018 164
The navigation drawer is a UI panel that shows your
app's main navigation menu. It is hidden when not in
use, but appears when the user swipes a finger from the
left edge of the screen or, when at the top level of the
app, the user touches the drawer icon in the app bar.
SSDN
21-07-2018 165
<?xml version="1.0" encoding="utf-8"?>
<!-- Use DrawerLayout as root container for activity -->
<android.support.v4.widget.DrawerLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/drawer_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true">
<FrameLayout
android:id="@+id/content_frame"
android:layout_width="match_parent"
android:layout_height="match_parent" />
<android.support.design.widget.NavigationView
android:id="@+id/nav_view"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_gravity="start"
android:fitsSystemWindows="true" />
SSDN
</android.support.v4.widget.DrawerLayout> 166
21-07-2018
<android.support.design.widget.NavigationView
android:id="@+id/nav_view"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_gravity="start"
android:fitsSystemWindows="true"
app:menu="@menu/drawer_view" />
SSDN
21-07-2018 167
<android.support.design.widget.NavigationView
android:id="@+id/nav_view"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_gravity="start"
android:fitsSystemWindows="true"
app:menu="@menu/drawer_view"
app:headerLayout="@layout/nav_header" />
SSDN
21-07-2018 168
class MainActivity : AppCompatActivity() {
mDrawerLayout = findViewById(R.id.drawer_layout)
true
SSDN
} 21-07-2018 169
}
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">
<android.support.v4.view.ViewPager
android:id="@+id/viewpager"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
</RelativeLayout>
SSDN
21-07-2018 170
ViewPager viewPager = (ViewPager)
findViewById(R.id.viewpager);
viewPager.setAdapter(new CustomPagerAdapter(this));
SSDN
21-07-2018 171
public enum ModelObject {
RED(R.string.red, R.layout.view_red), BLUE(R.string.blue,
R.layout.view_blue), GREEN(R.string.green,
R.layout.view_green);
private int mTitleResId;
private int mLayoutResId;
ModelObject(int titleResId, int layoutResId)
{
mTitleResId = titleResId; mLayoutResId = layoutResId; }
public int getTitleResId() {
return mTitleResId; }
public int getLayoutResId() {
return mLayoutResId;
}}
SSDN
21-07-2018 172
CustomAdapter.java
SSDN
21-07-2018 173
SSDN
21-07-2018 174
SSDN
21-07-2018 175