Posts

Sync Adapter Overview

Sync Adapter, as its name it is use to sync device data with server data. This sync can be done on following conditions:- When server data is changed. When device data is changed. At regular interval or specific time. On demand, such as user action. First lets understand SyncAapter Framework. Sync Adapter framework has 4 basic components :- Stub Authenticator. (For accessing account information.) Stub Content Provider (Used when your data is other than SQL) Syn Adapter (Entire Class runs in background thread. You on't need to create your own.) Binder Service (This allow sync adapter framework to call authenticator method.) Note:- Sync Adapter is not only used to sync SQL data, you can sync files, text, and other kind of data with sync adapter but for that need to use Stub Content Provider. Stub Authenticator  Now segregate all the information and come to the flow. So when request Sync. Binder service runs and called onPerformSync after authenticati

Software Design Principles (SOLID)

Image
Before moving on  Design Patterns  let's discuss few things about  Software Design Principles. What are Software Design Principles? Design Principles are set of guidelines that helps to design a software, which needs to avoid these  3 characteristics Rigidity :-  Your design is as flexible as it can be. Because if your design is rigid, your minor change will effect majorly in other part of system. Fragility :-  It means when you make a change in system,  unexpected part of system breaks . Immobility :-  Hard to reuse code in another application because its  tightly coupled . and follow these  Five Rules  ( SOLID) :- Single Responsibility Principle  A class should be designed with one goal but that doesn't mean it will have only one method. It simply means all methods are created to fulfill class goal. Also if we have more than one reason to change a class and (changes)they are not aligned with class goal, then it is better to split them in more than one cla

Doubts and Key Points of Run-time Permission in android

There are some key information related to permission architecture in android. Sometime it confuses developer on different API Versions. There are two type of permissions 1) Normal 2) Dangerous .All permission should be declared in Android Manifest File. You can find detail about it. Android introduced a Run-time Permission on device running API level 23 and above,whose targetSDKVersion is above or equal to 23. Normal permission needs to declare in manifest only. Dangerous or we can call them Privacy Permission also need to declare in manifest.  We also need to request these(Dangerous) permission at run-time. We can request it when user perform some specific operation related to that like opens camera, contacts and so on.  User can revoke run-time permission anytime from settings. These are the few key points of Android Permission. In this tutorial, I am not going to explain about implementation of Runtime Permission, there are already lots of tutorial and developer docs ava

Launch Stock Apps using Intent

Some time we have to launch stock applications in our android phone without need of performing some action. Like Email, Browser,Calculator,Calendar, Contacts, Gallery, Market and so on. This can be done by using power full function  makeMainSelectorActivity()  method   of Intent class. Syntax is pretty simple, just to write few lines of code Say you want to open email app. Intent intent= Intent . makeMainSelectorActivity ( Intent . ACTION_MAIN , Intent . CATEGORY_APP_EMAIL ); startActivity(intent); For other apps you just have to replace second parameter i.e. category. Here is some app listed category from android developer refernce CATEGORY_APP_BROWSER Used with  ACTION_MAIN  to launch the browser application. CATEGORY_APP_CALCULATOR Used with  ACTION_MAIN  to launch the calculator application. CATEGORY_APP_CALENDAR Used with  ACTION_MAIN  to launch the calendar application. CATEGORY_APP_CONTACTS Used with  ACTION_MAIN  to launch the contacts application

Draw Over Screen App Example Android

Image
We always interact with some app which are drawn over screen. Facebook Messenger is one of the good example of that. When you receive a new message it pops up over screen even if Messenger App is closed. So how to achieve this. This required very basic setup in your application. We are taking  targetSdkVersion 21  in build.gradle to avoid Runtime Permission implementation of SDK 23. Step 1 :- Give permission in your manifest file i.e. android.permission.SYSTEM_ALERT_WINDOW < uses-permission android :name= "android.permission.SYSTEM_ALERT_WINDOW" /> Step 2:- Then you have create your layout for overdraw window We are showing a button <?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android= "http://schemas.android.com/apk/res/android" android:orientation= "vertical" android:layout_width= "match_parent" android:layout_height= "wrap_content" android:grav

Basic concept of Content Provider

Definition :- Content Provider is one of the four component of android. Content provider mainly used to share data with other applications. You can also use this Content Provider within your application. What types of data can be shared through content provider's? You can share two types of data using Content Provider :- 1)  File Data  such as video, audio, text, data that is stored on your private space. 2)  Structured Data  i.e. stored in your application database (sql), array or similar data structure. Key Points:- It is used for secure data access between applications using Inter Process Communication. For accessing data from  provider of other applications, such as Contacts, Calendar, Browser, SearchRecentSuggestion Provider and so on. Synchronizing data with your server by using  AbstractThreadSynAdapter.   You can load data in UI using Cursor Loader. Sending data to widgets How to access a Content Provider? There are two ways to access content provider :-

Creating Simple Content Provider with Real-time Scenario

Hey guys, if you are here. Then i can expect that you have already gone through my blog about  Basic concepts of Content Provider . Which gives a brief understanding of content provider and its key concepts. Now we are going to explore content provider API much deeper. Here we are going to create a Simple Content Provider in our APP. Let say we are creating an application of tour and travel guide, hear user can search about tourist places and get information about that place. Suddenly we thought, why not to generate some revenue by sharing data of our app explored by user. So our business team suggested to share searched cities and places name's with other app's that having Train, Flight, Bus Hotel booking system. So that they show precise notifications, offer's to user for that places. Everything is done from business point of view. Then we discussed our tech team about feasibility of this task. They said, this is not a big deal we have to create a Content Provider