Chuyển đến nội dung chính

Bài đăng

Understanding the Android Application Class

Overview The  Application  class in Android is the base class within an Android app that contains all other components such as activities and services. The Application class, or any subclass of the Application class, is instantiated before any other class when the process for your application/package is created. This class is primarily used for initialization of global state before the first  Activity  is displayed. Note that custom  Application  objects should be used carefully and are often  not needed at all . Custom Application Classes In many apps, there's no need to work with an application class directly. However, there are a few acceptable uses of a custom application class: Specialized tasks that need to run before the creation of your first activity Global initialization that needs to be shared across all components (crash reporting, persistence) Static methods for easy access to static immutable data such as a shared network cl...

Retrofit Android Example Tutorial

Welcome to Retrofit Android Example Tutorial. Today we’ll use the  Retrofit  library developed by Square to handle REST API calls in our android application. Table of Contents  [ hide ] 1  Retrofit Android 2  OkHttp Interceptors 3  Setting Up the Retrofit Interface 4  Retrofit Android Example Project Structure Retrofit Android Retrofit is type-safe REST client for Android and Java which aims to make it easier to consume RESTful web services. We’ll not go into the details of Retrofit 1.x versions and jump onto  Retrofit 2  directly which has a lot of new features and a changed internal API compared to the previous versions. Retrofit 2 by default leverages  OkHttp  as the networking layer and is built on top of it. Retrofit automatically serialises the JSON response using a POJO(Plain Old Java Object) which must be defined in advanced for the JSON Structure. To serialise JSON we need a converter to convert it into...

Get You Last known Location & Current Location using FusedLocationProviderClient

NOVEMBER 30, 2017 Get You Last known Location & Current Location using FusedLocationProviderClient        I would like to cover very basic and simple example of retreiving last known location & Current Location  using Fused location API.  I have written many example for fused location API in my previous posts but in this post i will show how to get retrieve the location  without implementing Google Api Client . All these magics happen after the release of version  11.0.0 of Google Play services SDK. FusedLocationProviderApi is Deprecated We have previously used following way to retrieve the last known location. mLastLocation  =  LocationServices. FusedLocationApi . getLastLocation ( mGoogleApiClient ) ; We no need to define LocationServices. FusedLocationApi  anymore. it is deprecated. It will be removed in the future release. Instead You can use LocationServi...