2. CONTENTS
Introduction
Android Life Cycle
Activity
Fragment
Layout
Navigation Drawer
Recycler view
Shared preference
Api integration
3. INTRODUCTION
HISTORY OF ANDROID
Android Inc.founded in Palo Alto,california ,united states in October
2003 by Andy Rubin.(Rich Miner, Nick sears and Chris white)
WHAT IS ANDROID?
It is a open source software platform and operating system for mobile
devices , Based on the Linux kernel . Developed by Google and later the
Open Handset Alliance (OHA).
5. Android version history
Code name Version no. Release date API Level
No codename 1.0 September 23, 2008 1
No codename 1.1 February 9, 2009 2
Cupcake 1.5 April 27, 2009 3
Donut 1.6 September 15, 2009 4
Eclair 2.0 – 2.1 October 26, 2009 5-7
Froyo 2.2 – 2.1 May 20, 2010 8
Gingerbread 2.3 – 2.3.7 December 6, 2010 9-10
Honeycomb 3.0 – 3.2.6 February 22, 2011 11-13
Ice Cream Sandwich 4.0 – 4.0.4 October 18, 2011 14-15
Jelly Bean 4.1 – 4.3.1 July 9, 2012 16-18
KitKat 4.4 – 4.4.4 October 31, 2013 19-20
Lollipop 5.0 - 5.1.1 November 12, 2014 21-22
Mashmallow 6.0 – 6.0.1 October 5, 2015 23
Nougat 7.0 – 7.1.2 August 22, 2016 24-25
Oreo 8.0 August 21, 2017 26
6. ANDROID LIFE CYCLE
The steps that an application goes through from starting to finishing
onCreate()
onRestart
onStart()
onResume()
onStop()
onPause()
onDestroy
7.
8. ANDROID LIFE CYCLE
onCreate() - Called before the first components of the application starts.
onRestart - Called after your activity has been stopped, prior to it being
started again.
onStart() – Called when the activity is becoming visible to the user.
onResume() - Called if the activity get visible again.
onStop() - Called once the activity is no longer visible.
onPause() - Called once another activity gets into the foreground.
onDestroy - The final call you receive before your activity is destroyed.
9. ACTIVITY
Basic component of most applications
Most applications have several activities that start each other as needed
Each is implemented as a subclass of the base Activity class
The content of the window is a view or a group of views
Example of views: buttons, text fields, scroll bars, menu items, check boxes,
etc.
An activity is started by Context.startActivity(Intent intent) or
Activity.startActivityForResult(Intent intent, int RequestCode)
10. package com.twixt.uaeexportdirectory.view.activity;
import android.os.Bundle;
import android.os.PersistableBundle;
import android.support.annotation.Nullable;
import android.support.v7.app.AppCompatActivity;
/**
* @author Pranav Ashok on 30-09-2017.
*/
public class Activity extends AppCompatActivity{
@Override
public void onCreate(@Nullable Bundle savedInstanceState, @Nullable PersistableBundle persistentState) {
super.onCreate(savedInstanceState, persistentState);
setContentView(R.layout.activity_xml);
}
}
ACTIVITY
11. FRAGMENT
About Fragments
New in Android 3.0 (Honeycomb, API 11)
Intended to reuse layouts between tablets and phones But usable for many
more...
A fragment is a modular section of an activity, which has its own lifecycle.
A fragment's lifecycle is directly affected by the host activity's lifecycle
Activity paused: fragments paused
Activity destroyed: fragments destroyed
Activity running: fragments can have different states
13. FRAGMENT LIFECYCLE
onAttach() :This method will be called first, even before onCreate(), letting
us know that your fragment has been attached to an activity.
onCreate() : The system calls this when creating the fragment.
onCreateView() : The system calls this when it's time for the fragment to
draw its user interface for the first time.
onViewCreated() : This will be called after onCreateView().
onPause() : The system calls this method as the first indication that the user
is leaving the fragment (though it does not always mean the fragment is being
destroyed).
onDestroyView() : It’s called before onDestroy().
14. package com.twixt.uaeexportdirectory.view.activity;
import android.os.Bundle;
import android.os.PersistableBundle;
import android.support.annotation.Nullable;
import android.support.v7.app.AppCompatActivity;
/**
* @author Pranav Ashok on 30-09-2017.
*/
public class Activity extends AppCompatActivity{
@Override
public void onCreate(@Nullable Bundle savedInstanceState, @Nullable PersistableBundle
persistentState) {
super.onCreate(savedInstanceState, persistentState);
setContentView(R.layout.activity_xml);
//type your code here
}
}
FRAGMENT
getFragmentManager().beginTransaction()
.add(R.id.activity_xml, new YourFragment(), Activity.class.getName())
.commit();
15. package com.twixt.uaeexportdirectory.view.activity;
import android.app.Fragment;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import com.xtronlabs.uaeexportdirectory.R;
/**
* @author Pranav Ashok on 30-09-2017.
*/
public class YourFragment extends Fragment{
@Nullable
@Override
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, Bundle
savedInstanceState) {
View view=inflater.inflate(R.layout.your_fragment_xml,container,false);
return view;
}
}
FRAGMENT
16. LAYOUT
What is a Layout?
Your layout is the architecture for the user interface in an Activity.
It defines the layout structure and holds all the elements that appear
to the user.
How to declare a Layout?
Option #1: Declare UI elements in XML
Option #2: Instantiate layout elements at runtime
22. RECYCLERVIEW
This widget is a container for displaying large data sets that can be scrolled
very efficiently by maintaining a limited number of views.
You need to include gradle file in the dependencies (build.gradle module)
Compile 'com.android.support:recyclerview-v7:25.+'
24. RECYCLERVIEW
public Rv_Adapter rv_Adapter;
public RecyclerView r_v;
Rv_Adapter = new Rv_Adapter (getActivity());
r_v.setAdapter(rv_Adapter);
r_v.setLayoutManager(new LinearLayoutManager(getActivity()));
//in main xml page
<android.support.v7.widget.RecyclerView
android:id="@+id/rv_id"
android:layout_width="match_parent"
android:layout_height="wrap_content“/>
25.
26. SHARED PREFERENCE
The shared preference is a class that provide a storage area to store a small
amount of temporary data you can save.
Shared preference in Android are used to keep track of application and user
preferences.
Android applications can store data in application 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, intdefVal).
We can modify the SharedPreference instance in our case using the <br
/>edit() and use the putInt(String key, intnewVal)
28. API INTEGRATION
Connect to the Network
<uses-permission android:name="android.permission.INTERNET" />
Manage Network Usage
Minimize the amount of sensitive or personal user data that you transmit
over the network.
Parsing XML Data
Integrate data in your xml fields
29. API INTEGRATION
Things to remember before integrating
In manifests
<uses-permission android:name="android.permissionINTERNET" />
In build.gradle(Module:app)
packagingOptions {
packagingOptions {
exclude 'META-INF/DEPENDENCIES'
exclude 'META-INF/NOTICE'
exclude 'META-INF/LICENSE'
exclude 'META-INF/LICENSE.txt'
exclude 'META-INF/NOTICE.txt'
}
}
31. API INTEGRATION
Create an Interface Class
public interface Interface_all_links_here {
@GET("aps_api/get_all_ads")
Call<Api_Responce[]> getDATA();
}
32. API INTEGRATION
Create an Interface Class for processor responce
public interface ProcessResponceIntrphase<T> {
void processResponce(T responce);
}
34. API INTEGRATION
Create an Rrequest Class for Api
public class Api_Request extends AbstractRequest<Api_Responce[]> {
public Api_Request(Context context,
ProcessResponceIntrphase<Api_Responce[]> responcec_Handeler) {
super(context, responcec_Handeler);
}
public void get_Data() {
Call<Api_Responce[]> call = _interface.getDATA();
call.enqueue(this);
}
}
public class Adapter_for_rv extends RecyclerView.Adapter<Adapter_for_rv.ViewHolder> {
Context context;
public Adapter_for_rv(Context con) {
context = con;
}
@Override
public Adapter_for_rv.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
LayoutInflater layoutInflater = LayoutInflater.from(context);
return new ViewHolder(layoutInflater.inflate(R.layout.rvlayout, parent, false));
}
@Override
public void onBindViewHolder(Adapter_for_rv.ViewHolder holder, int position) {
//code -> action to be done
}
@Override
public int getItemCount() {
return length;
}
public class ViewHolder extends RecyclerView.ViewHolder {
// declarations
public ViewHolder(final View itemView) {
super(itemView);
// finding declared fields and actions here
}
}
}