How to use Retrofit to get data from stackoverflow API and GitHub Demo in android studio

Retrofit is a type-safe REST client for Android developed by Square. The library provides a powerful framework for authenticating and interacting with APIs and sending network requests with OkHttp. See this guide to understand how OkHttp works.

This library makes downloading JSON or XML data from a web API fairly straightforward. Once the data is downloaded then it is parsed into a Plain Old Java Object (POJO) which must be defined for each "resource" in the response.

Setup
Must be defined on internet permission on AndroidManifest.xml .


Dependencies
Add following dependencies on app/build.gradle file:



Converter:
Here is the different type of  Gson converter, we can use them:



How to create retrofit instance, 
then we have to define, the userendpoint:
Now, create model class, user variables, In MainActivity.java, we have to create instance of APIClient and call the users.

Download Full code: https://github.com/dharmakshetri/Android-API-Demos
and you can find out Awesome Retrofit Article: Retrofit Tutorial With Example In Android Studio [Step by Step]
More details:
https://square.github.io/retrofit/
https://github.com/square/retrofit
https://guides.codepath.com/android/Consuming-APIs-with-Retrofit
https://realm.io/news/droidcon-jake-wharton-simple-http-retrofit-2/
http://www.vogella.com/tutorials/Retrofit/article.html


Happy Coding !!!

What’s new – Material design (December 2016)

In the Material design in August 2016, three Notifications, Widgets and Confirmation and acknowledgement.
source:matrial.io

Now in December 2016, In Material design here is the latest added new section and significance updates.

New sections
  • Platforms discusses when and how to adapt apps to Material Design, and when to adhere to platform conventions
  • App shortcut icons contains specs on how to create app shortcut icons for the home screen
  • Help and feedback describes how to indicate, craft, and place help content
Significant updates
  • Bidirectionality has updated guidance on mirroring UI content and icons in right-to-left (RTL) languages
  • Accessibility contains new guidance on sound, controls, labeling elements, and testing
  • Selection includes detailed examples on item selection, toggling, and styling
Happy Coding !!!

Firebase: Save, Delete and Retrieve data from firebase database in Android Studio

In Firebase Realtime Database we can store and sync data with our NoSQL cloud database. Data is synced across all clients in realtime, and remains available when your app goes offline.

The Firebase Realtime Database is a cloud-hosted database. Data is stored as JSON and synchronized in realtime to every connected client. When you build cross-platform apps with our iOS, Android, and JavaScript SDKs, all of your clients share one Realtime Database instance and automatically receive updates with the newest data.

Android Setup

Here is the one example how to store on firebase and retrieve data on your android device.

First step Create firebase project  from https://console.firebase.google.com.

Add the dependency for Firebase Realtime Database to your app-level build.gradle file:



Update the rules for your database to allow reads and writes from all users, as this demo will not cover Firebase Authentication.


Steps:
1. Create firebase database reference
2. Get data from your form
3. Add and push data on database
4. Update on your view using creating anonymous inner class ChildEventListener.
5. Check you firebase database

Here is the full code:





Update on recyclerview, which show in below git hub link.

Output Snapshots:




Clone the github java
$git clone https://github.com/dharmakshetri/FirebaseAddOrDeleteonDatabase.git

Happy Coding !!!


RxAndroid Example to display data on RecyclerView in Android Studio

RxAndroid is simple in one term is reactive extension for android.
Android authorities defined, Observables and Observers in terms of RxAndrod, There are two basic and very important items in reactive programming, Observables and Observers. Observables publish values, while Observers subscribe to Observables, watching them and reacting when an Observable publishes a value.

In simpler terms:

    An Observable performs some action, and publishes the result.
    An Observer waits and watches the Observable, and reacts whenever the Observable publishes results.

There are three different changes that can occur on an Observable that the Observer reacts to. These are:


  1.     Publishing a value
  2.     Throwing an error
  3.     Completed publishing all values


A class that implements the Observer interface must provide methods for each of the three changes above:


  1.     An onNext() method that the Observable calls whenever it wishes to publish a new value
  2.     An onError() method that’s called exactly once, when an error occurs on the Observable.
  3.     An onCompleted() method that’s called exactly once, when the Observable completes execution.

Example: Display list of data using RxAndroid in to RecyclerView

First you have to import the dependencies  latest version of RxAndrod, RxJava and other like recyclerview, in to the build.gradle on app level inside the dependencies section.


Layout:
 RecyclerView is simply A flexible view for providing a limited window into a large data set.
activity_main.xml


and custom list item layout



Now, Obserable implement on MainActivity,



and Now implement RecyclerView Adapter



Output looks like:


Download full code from github: RxAndroid_RecyclerView_Example

Happy Coding!!!