SlideShare una empresa de Scribd logo
1 de 38
ANDROID
Prepared By
Pranav Ashok
Android developer
CONTENTS
 Introduction
 Android Life Cycle
 Activity
 Fragment
 Layout
 Navigation Drawer
 Recycler view
 Shared preference
 Api integration
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).
INTRODUCTION
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
ANDROID LIFE CYCLE
 The steps that an application goes through from starting to finishing
 onCreate()
 onRestart
 onStart()
 onResume()
 onStop()
 onPause()
 onDestroy
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.
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)
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
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
FRAGMENT LIFECYCLE
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().
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();
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
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
LAYOUT
Types of Layouts
 RelativeLayout
 LinearLayout
 FrameLayout
 GridLayout
 TableLayout
 ConstraintLayout
NAVIGATION DRAWER
 For opening drawer (using java code)
drawer_layout_id.openDrawer(Gravity.LEFT);
drawerLayout.openDrawer(Gravity.RIGHT);
 For closing drawer (using java code)
drawer_layout_id.closeDrawers();
NAVIGATION DRAWER
RECYCLERVIEW
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.+'
RECYCLERVIEW
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“/>
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)
SHARED PREFERENCE
SharedPreferences sp =
getActivity().getSharedPreferences("sp_file",Context.MODE_PRIVATE);
String i=sp.getString (“key", “default string");
SharedPreferences s_p =
getActivity().getSharedPreferences(“sp_file",Context.MODE_PRIVATE);
SharedPreferences.Editor editor=s_p.edit();
editor.putString(“key", " your_string ");
editor.commit();
//default SharedPreference
SharedPreferences sp =
getActivity().PreferenceManager.getDeaultSharedPreferences(this);
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
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'
}
}
API INTEGRATION
compile 'com.squareup.retrofit2:retrofit:2.1.0'
compile 'com.squareup.okhttp3:logging-interceptor:3.6.0'
compile 'com.squareup.retrofit2:converter-jackson:2.1.0'
Things to remember before integrating
 In build.gradle(Module:app)
API INTEGRATION
 Create an Interface Class
public interface Interface_all_links_here {
@GET("aps_api/get_all_ads")
Call<Api_Responce[]> getDATA();
}
API INTEGRATION
 Create an Interface Class for processor responce
public interface ProcessResponceIntrphase<T> {
void processResponce(T responce);
}
API INTEGRATION
 Create an Rrequest Class for Api
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);
}
}
API INTEGRATION
 Create an Response Class for Api
API INTEGRATION
 Main activity/fragement
TIPS FOR BEGINNER
 Accounts
 https://stackoverflow.com
 https://github.com
 References
 https://www.tutorialspoint.com/android
 https://developer.android.com/training/index.html
 https://www.javatpoint.com/android-tutorial
 https://www.youtube.com
Android

Más contenido relacionado

La actualidad más candente

android activity
android activityandroid activity
android activity
Deepa Rani
 
Android Development project
Android Development projectAndroid Development project
Android Development project
Minhaj Kazi
 
Google Plus SignIn : l'Authentification Google
Google Plus SignIn : l'Authentification GoogleGoogle Plus SignIn : l'Authentification Google
Google Plus SignIn : l'Authentification Google
Mathias Seguy
 

La actualidad más candente (18)

Anatomy of android application
Anatomy of android applicationAnatomy of android application
Anatomy of android application
 
android activity
android activityandroid activity
android activity
 
Android apps development
Android apps developmentAndroid apps development
Android apps development
 
Introduction to Android Fragments
Introduction to Android FragmentsIntroduction to Android Fragments
Introduction to Android Fragments
 
Android Fragment
Android FragmentAndroid Fragment
Android Fragment
 
Presentation on Android application life cycle and saved instancestate
Presentation on Android application life cycle and saved instancestatePresentation on Android application life cycle and saved instancestate
Presentation on Android application life cycle and saved instancestate
 
Activities, Fragments, and Events
Activities, Fragments, and EventsActivities, Fragments, and Events
Activities, Fragments, and Events
 
Introduction to fragments in android
Introduction to fragments in androidIntroduction to fragments in android
Introduction to fragments in android
 
[Individual presentation] android fragment
[Individual presentation] android fragment[Individual presentation] android fragment
[Individual presentation] android fragment
 
04 activities - Android
04   activities - Android04   activities - Android
04 activities - Android
 
Android Tutorial For Beginners Part-1
Android Tutorial For Beginners Part-1Android Tutorial For Beginners Part-1
Android Tutorial For Beginners Part-1
 
Android Development project
Android Development projectAndroid Development project
Android Development project
 
Android - Working with Fragments
Android - Working with FragmentsAndroid - Working with Fragments
Android - Working with Fragments
 
Google Plus SignIn : l'Authentification Google
Google Plus SignIn : l'Authentification GoogleGoogle Plus SignIn : l'Authentification Google
Google Plus SignIn : l'Authentification Google
 
Android by Swecha
Android by SwechaAndroid by Swecha
Android by Swecha
 
Fragments: Why, How, What For?
Fragments: Why, How, What For?Fragments: Why, How, What For?
Fragments: Why, How, What For?
 
Android 3
Android 3Android 3
Android 3
 
Android App Development - 06 Fragments
Android App Development - 06 FragmentsAndroid App Development - 06 Fragments
Android App Development - 06 Fragments
 

Similar a Android

android training_material ravy ramio
android training_material ravy ramioandroid training_material ravy ramio
android training_material ravy ramio
slesulvy
 
Answer1)Responsive design is the idea where all the developed pag.pdf
Answer1)Responsive design is the idea where all the developed pag.pdfAnswer1)Responsive design is the idea where all the developed pag.pdf
Answer1)Responsive design is the idea where all the developed pag.pdf
ankitcomputer11
 
Android activity, service, and broadcast recievers
Android activity, service, and broadcast recieversAndroid activity, service, and broadcast recievers
Android activity, service, and broadcast recievers
Utkarsh Mankad
 

Similar a Android (20)

Introduction to Android Development
Introduction to Android DevelopmentIntroduction to Android Development
Introduction to Android Development
 
Stmik bandung
Stmik bandungStmik bandung
Stmik bandung
 
android training_material ravy ramio
android training_material ravy ramioandroid training_material ravy ramio
android training_material ravy ramio
 
Answer1)Responsive design is the idea where all the developed pag.pdf
Answer1)Responsive design is the idea where all the developed pag.pdfAnswer1)Responsive design is the idea where all the developed pag.pdf
Answer1)Responsive design is the idea where all the developed pag.pdf
 
Android terminologies
Android terminologiesAndroid terminologies
Android terminologies
 
Android activity, service, and broadcast recievers
Android activity, service, and broadcast recieversAndroid activity, service, and broadcast recievers
Android activity, service, and broadcast recievers
 
"Android" mobilių programėlių kūrimo įvadas #2
"Android" mobilių programėlių kūrimo įvadas #2"Android" mobilių programėlių kūrimo įvadas #2
"Android" mobilių programėlių kūrimo įvadas #2
 
Android Development Basics
Android Development BasicsAndroid Development Basics
Android Development Basics
 
Activity
ActivityActivity
Activity
 
Activity
ActivityActivity
Activity
 
Activity
ActivityActivity
Activity
 
Android
AndroidAndroid
Android
 
Android apps development
Android apps developmentAndroid apps development
Android apps development
 
Android best practices
Android best practicesAndroid best practices
Android best practices
 
Android beginners David
Android beginners DavidAndroid beginners David
Android beginners David
 
Synapseindia android application development tutorial
Synapseindia android application development tutorialSynapseindia android application development tutorial
Synapseindia android application development tutorial
 
Synapseindia android apps development tutorial
Synapseindia android apps  development tutorialSynapseindia android apps  development tutorial
Synapseindia android apps development tutorial
 
What's New in Android
What's New in AndroidWhat's New in Android
What's New in Android
 
Native Android Development Practices
Native Android Development PracticesNative Android Development Practices
Native Android Development Practices
 
02 hello world - Android
02   hello world - Android02   hello world - Android
02 hello world - Android
 

Último

The basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxThe basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptx
heathfieldcps1
 
Making and Justifying Mathematical Decisions.pdf
Making and Justifying Mathematical Decisions.pdfMaking and Justifying Mathematical Decisions.pdf
Making and Justifying Mathematical Decisions.pdf
Chris Hunter
 
1029 - Danh muc Sach Giao Khoa 10 . pdf
1029 -  Danh muc Sach Giao Khoa 10 . pdf1029 -  Danh muc Sach Giao Khoa 10 . pdf
1029 - Danh muc Sach Giao Khoa 10 . pdf
QucHHunhnh
 
Gardella_PRCampaignConclusion Pitch Letter
Gardella_PRCampaignConclusion Pitch LetterGardella_PRCampaignConclusion Pitch Letter
Gardella_PRCampaignConclusion Pitch Letter
MateoGardella
 

Último (20)

Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
 
The basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxThe basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptx
 
microwave assisted reaction. General introduction
microwave assisted reaction. General introductionmicrowave assisted reaction. General introduction
microwave assisted reaction. General introduction
 
Sports & Fitness Value Added Course FY..
Sports & Fitness Value Added Course FY..Sports & Fitness Value Added Course FY..
Sports & Fitness Value Added Course FY..
 
Measures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and ModeMeasures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and Mode
 
fourth grading exam for kindergarten in writing
fourth grading exam for kindergarten in writingfourth grading exam for kindergarten in writing
fourth grading exam for kindergarten in writing
 
Making and Justifying Mathematical Decisions.pdf
Making and Justifying Mathematical Decisions.pdfMaking and Justifying Mathematical Decisions.pdf
Making and Justifying Mathematical Decisions.pdf
 
Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17
 
Unit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptxUnit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptx
 
ICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptxICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptx
 
Unit-IV; Professional Sales Representative (PSR).pptx
Unit-IV; Professional Sales Representative (PSR).pptxUnit-IV; Professional Sales Representative (PSR).pptx
Unit-IV; Professional Sales Representative (PSR).pptx
 
SECOND SEMESTER TOPIC COVERAGE SY 2023-2024 Trends, Networks, and Critical Th...
SECOND SEMESTER TOPIC COVERAGE SY 2023-2024 Trends, Networks, and Critical Th...SECOND SEMESTER TOPIC COVERAGE SY 2023-2024 Trends, Networks, and Critical Th...
SECOND SEMESTER TOPIC COVERAGE SY 2023-2024 Trends, Networks, and Critical Th...
 
1029 - Danh muc Sach Giao Khoa 10 . pdf
1029 -  Danh muc Sach Giao Khoa 10 . pdf1029 -  Danh muc Sach Giao Khoa 10 . pdf
1029 - Danh muc Sach Giao Khoa 10 . pdf
 
Accessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactAccessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impact
 
psychiatric nursing HISTORY COLLECTION .docx
psychiatric  nursing HISTORY  COLLECTION  .docxpsychiatric  nursing HISTORY  COLLECTION  .docx
psychiatric nursing HISTORY COLLECTION .docx
 
How to Give a Domain for a Field in Odoo 17
How to Give a Domain for a Field in Odoo 17How to Give a Domain for a Field in Odoo 17
How to Give a Domain for a Field in Odoo 17
 
Z Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot GraphZ Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot Graph
 
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
 
Gardella_PRCampaignConclusion Pitch Letter
Gardella_PRCampaignConclusion Pitch LetterGardella_PRCampaignConclusion Pitch Letter
Gardella_PRCampaignConclusion Pitch Letter
 
Advance Mobile Application Development class 07
Advance Mobile Application Development class 07Advance Mobile Application Development class 07
Advance Mobile Application Development class 07
 

Android

  • 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
  • 17. LAYOUT Types of Layouts  RelativeLayout  LinearLayout  FrameLayout  GridLayout  TableLayout  ConstraintLayout
  • 18.
  • 19. NAVIGATION DRAWER  For opening drawer (using java code) drawer_layout_id.openDrawer(Gravity.LEFT); drawerLayout.openDrawer(Gravity.RIGHT);  For closing drawer (using java code) drawer_layout_id.closeDrawers();
  • 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)
  • 27. SHARED PREFERENCE SharedPreferences sp = getActivity().getSharedPreferences("sp_file",Context.MODE_PRIVATE); String i=sp.getString (“key", “default string"); SharedPreferences s_p = getActivity().getSharedPreferences(“sp_file",Context.MODE_PRIVATE); SharedPreferences.Editor editor=s_p.edit(); editor.putString(“key", " your_string "); editor.commit(); //default SharedPreference SharedPreferences sp = getActivity().PreferenceManager.getDeaultSharedPreferences(this);
  • 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' } }
  • 30. API INTEGRATION compile 'com.squareup.retrofit2:retrofit:2.1.0' compile 'com.squareup.okhttp3:logging-interceptor:3.6.0' compile 'com.squareup.retrofit2:converter-jackson:2.1.0' Things to remember before integrating  In build.gradle(Module:app)
  • 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); }
  • 33. API INTEGRATION  Create an Rrequest Class for Api
  • 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); } }
  • 35. API INTEGRATION  Create an Response Class for Api
  • 36. API INTEGRATION  Main activity/fragement
  • 37. TIPS FOR BEGINNER  Accounts  https://stackoverflow.com  https://github.com  References  https://www.tutorialspoint.com/android  https://developer.android.com/training/index.html  https://www.javatpoint.com/android-tutorial  https://www.youtube.com

Notas del editor

  1. <?xml version="1.0" encoding="utf-8"?> <android.support.v4.widget.DrawerLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent"> <RelativeLayout android:layout_width="match_parent" android:layout_height="match_parent" android:background="#00e4c9"> <android.support.v7.widget.RecyclerView android:layout_width="match_parent" android:background="@color/colorAccent" android:alpha=".6" android:layout_margin="5dp" android:layout_height="match_parent" /> </RelativeLayout> <RelativeLayout android:layout_width="200dp" android:layout_height="match_parent" android:layout_gravity="left" android:background="#6200ff"> </RelativeLayout> <RelativeLayout android:layout_width="200dp" android:layout_height="match_parent" android:layout_gravity="right" android:background="#ff6f00"> </RelativeLayout> </android.support.v4.widget.DrawerLayout>
  2. 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 } } }
  3. package com.twixt.nd; import android.content.Context; import android.util.Log; import java.util.concurrent.TimeUnit; import okhttp3.OkHttpClient; import okhttp3.logging.HttpLoggingInterceptor; import retrofit2.Call; import retrofit2.Callback; import retrofit2.Response; import retrofit2.Retrofit; import retrofit2.converter.jackson.JacksonConverterFactory; /** * @author pranav Ashok on 06-10-2017. */ public abstract class AbstractRequest<T> implements Callback<T> { private static final String base_url = "http://apps.cloudsoftct.com/"; protected Context context; protected Interface_all_links_here _interface; private ProcessResponceIntrphase<T> responcehandler; public AbstractRequest(Context con,ProcessResponceIntrphase<T> rhandler){ context= con; responcehandler =rhandler; HttpLoggingInterceptor loggingInterceptor = new HttpLoggingInterceptor(); loggingInterceptor.setLevel(HttpLoggingInterceptor.Level.BODY); Retrofit retrofit= new Retrofit.Builder() .baseUrl(base_url) .client(new OkHttpClient.Builder().addNetworkInterceptor(loggingInterceptor) .connectTimeout(300, TimeUnit.SECONDS) .readTimeout(300,TimeUnit.SECONDS) .build()) .addConverterFactory(JacksonConverterFactory.create()) .build(); _interface=retrofit.create(Interface_all_links_here.class); } @Override public void onResponse(Call<T> call, Response<T> response) { Log.e("response", " ok"); processResponse(response.body()); } @Override public void onFailure(Call<T> call, Throwable t) { Log.e("response ", t.getMessage()+" poe"); processResponse(null); } private void processResponse(T response){ if(responcehandler != null){ responcehandler.processResponce(response); } } }