<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Maitri Varia on Medium]]></title>
        <description><![CDATA[Stories by Maitri Varia on Medium]]></description>
        <link>https://medium.com/@maitri.varia?source=rss-75331172b793------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/0*hGgxoVxBo763wePs.jpg</url>
            <title>Stories by Maitri Varia on Medium</title>
            <link>https://medium.com/@maitri.varia?source=rss-75331172b793------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sun, 06 Dec 2026 12:57:27 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@maitri.varia/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Flutter —]]></title>
            <link>https://blog.nonstopio.com/flutter-b8e2ea73f587?source=rss-75331172b793------2</link>
            <guid isPermaLink="false">https://medium.com/p/b8e2ea73f587</guid>
            <category><![CDATA[firebase]]></category>
            <category><![CDATA[google-signin]]></category>
            <category><![CDATA[flutter-app-development]]></category>
            <category><![CDATA[mobile-apps]]></category>
            <category><![CDATA[firebaseauthentication]]></category>
            <dc:creator><![CDATA[Maitri Varia]]></dc:creator>
            <pubDate>Mon, 31 May 2021 17:35:23 GMT</pubDate>
            <atom:updated>2021-06-01T06:26:58.975Z</atom:updated>
            <content:encoded><![CDATA[<h3>Flutter: Google sign-in</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*U9xipEbfDKY54tg6OI-8fA.jpeg" /><figcaption>source: https://google.com</figcaption></figure><p>Hey folks, I am coming with another blog for Flutter development. Today, I will show you how how to implement/add Google sign-in with firebase to your Flutter apps.</p><p><strong>Getting started</strong></p><p>First of all, create a new Flutter project, and then we will add the required packages and assets to the project. Also, you will need to register your application in the <a href="https://firebase.google.com/">firebase console</a>.</p><p><strong>Steps to implement Firebase Authentication:-</strong></p><ol><li>Open the Firebase console and click on the Add project.</li><li>Specify the project name and click on the continue.</li><li>If you want to apply google analytics for your project then keep the radio button checked and click on create project button. This is an optional field.</li><li>Once the project is created click on the continue button.</li><li>You will be redirected to the project overview screen.</li><li>Now, click on Authentication from the left menu and select the sign-in method.</li><li>Now, select Google from the list and click on the enable.</li></ol><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*qjBePm56Tnf-sPBFhupnXg.png" /></figure><ol><li>Now, add the SHA1 key for your project in the general tab from the project settings screen.</li></ol><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*BjEXD9RzWekB_EknIqnA7w.png" /></figure><p><strong>Required Plugins</strong></p><p>Add below plugins to your pubspec.yaml file.</p><pre>screen_loader: ^2.0.0<br>after_layout: ^1.0.7+2<br>ns_utils: 0.0.3<br>cached_network_image: 2.5.0<br>firebase_core: ^0.5.3<br>firebase_auth: ^0.18.4+1<br>firebase_storage: ^5.2.0<br>google_sign_in: ^4.5.6<br>cloud_firestore: ^0.14.4<br>connectivity_wrapper: ^1.0.4<br>connectivity: ^2.0.2</pre><ol><li><strong>screen_loader:-</strong> Display loaders in the application.</li><li><strong>after_layout:-</strong> Brings functionality to execute code after the first layout of a widget has been performed, i.e. after the first frame has been displayed.</li><li><strong>ns_utils:- </strong>Set of methods/extensions for flutter that makes using a framework in a much easier and cleaner way also adds additional functionality.</li><li><strong>firebase_core, firebase_auth, firebase_storage :-</strong> To perform firebase related operations.</li><li><strong>google_sign_in:-</strong> A flutter plugin for google sign-in.</li><li><strong>connectivity_wrapper:- </strong>Plugin allows Flutter apps to provide feedback on your app when it’s not connected to it, or when there’s no connection.</li><li><strong>connectivity:- </strong>This plugin allows Flutter apps to discover network connectivity and configure themselves accordingly. It can distinguish between cellular vs WiFi connections.</li></ol><p>Now, run <strong><em>flutter packages get </em></strong><em>a</em><strong><em> </em></strong><em>command to save them.</em></p><p>Let’s implement the code for google_sign_in.</p><pre>Future&lt;Null&gt; loginWithGoogle(BuildContext ctx) async {<br>  final fireStoreInstance = FirebaseFirestore.<em>instance</em>;<br>  FirebaseAuth _auth = FirebaseAuth.<em>instance</em>;<br>  GoogleSignIn googleSignIn = GoogleSignIn();</pre><pre>  try {<br>    GoogleSignInAccount account = await googleSignIn.signIn();<br>    GoogleSignInAuthentication authentication = await account.authentication;<br><br>    AuthCredential credential = GoogleAuthProvider.<em>credential</em>(<br>        accessToken: authentication.accessToken,<br>        idToken: authentication.idToken);<br><br>    UserCredential userCredential =<br>        await _auth.signInWithCredential(credential);<br>    User user = userCredential.user;<br><br>    if (user != null) {<br>      appLogs(user.uid);<br>      DocumentSnapshot snapshot = await fireStoreInstance<br>          .collection(AppKeys.<em>userCollection</em>)<br>          .doc(user.uid)<br>          .get();<br><br>      if (snapshot.exists) {<br>        appLogs(Strings.<em>logSameUser</em>);<br><br>        localUser.User.fromMap(snapshot.data());<br>        SPService.<em>instance</em>.setString(Strings.<em>userId</em>, user.uid);<br>        ctx.replace(HomeScreen());<br>      } else {<br>        appLogs(Strings.<em>logDifferentUser</em>);<br>        saveUserData(user, ctx);<br>      }<br>    }<br>  } catch (e) {<br>    print(e);<br>  }<br>  return null;<br>}</pre><pre>// Stroing user data.<br>Future&lt;Null&gt; saveUserData(User user, BuildContext context) async {<br>  fireStoreInstance.collection(AppKeys.<em>userCollection</em>).doc(user.uid).set({<br>    AppKeys.<em>name</em>: user.displayName,<br>    AppKeys.<em>email</em>: user.email,<br>    AppKeys.<em>profilePic</em>: user.photoURL,<br>    AppKeys.<em>isEmailVerified</em>: user.emailVerified<br>  }).then((_) async {<br>    appLogs(Strings.<em>success</em>);<br>    if (SPService.<em>instance </em>!= null)<br>      await SPService.<em>instance</em>.setString(Strings.<em>userId</em>, user.uid);<br>    context.replace(HomeScreen());<br>  });<br>}</pre><pre>// Logout from google.<br>Future&lt;void&gt; logoutFromGoogle(BuildContext context) async {<br>  try {<br>    SPService.<em>instance</em>.clear();<br>    localUser.User.empty();<br>    await googleSignIn.signOut();<br>    context.makeFirst(LoginScreen(), isCupertino: true);<br>  } catch (e, s) {<br>    appLogs(&#39;$e\n$s&#39;);<br>  }<br>}</pre><p>I have created 3 different methods to perform operations.</p><ol><li>loginWithGoogle():- This method will perform google sign-in for the given credentials. Also, it will check if a user is already registered in the application. If the user is already registered then it will directly move to the dashboard screen and if not then the user&#39;s data will be stored in the firebase, and then the user will be redirected to the dashboard screen.</li><li>saveUserData:- Here for demo purposes, I am storing the user’s email, name, and profile picture to the firebase. Also, user’s data will be stored in shared preferences using SPService class.</li><li>logoutFromGoogle:- It will logs out the user from the application and also clearing and emptying the user data in the shared preferences.</li></ol><p>Now, run the application, we are done 🎉</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Ac8PpybusDVvN9uzP7Bk4w.jpeg" /></figure><p>Thank you for your valuable time, if you found this useful then don’t forget to add a clap 👏. Do follow me on Medium to get the latest updates.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=b8e2ea73f587" width="1" height="1" alt=""><hr><p><a href="https://blog.nonstopio.com/flutter-b8e2ea73f587">Flutter —</a> was originally published in <a href="https://blog.nonstopio.com/">nonstopio</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Expand/collapse views in Flutter]]></title>
            <link>https://blog.nonstopio.com/expand-collapse-views-in-flutter-a93699ec7366?source=rss-75331172b793------2</link>
            <guid isPermaLink="false">https://medium.com/p/a93699ec7366</guid>
            <category><![CDATA[flutter-app-development]]></category>
            <category><![CDATA[mobile-app-development]]></category>
            <category><![CDATA[flutter-widget]]></category>
            <category><![CDATA[flutter]]></category>
            <dc:creator><![CDATA[Maitri Varia]]></dc:creator>
            <pubDate>Wed, 02 Dec 2020 08:58:53 GMT</pubDate>
            <atom:updated>2020-12-02T08:58:53.245Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/640/1*kAIDgxyhaIpSDrt0X87GjA.jpeg" /><figcaption><a href="https://www.google.com/">https://www.google.com/</a></figcaption></figure><p>Hello, sometimes in app development, we may have a requirement to hide/show views. To expand/collapse views in Flutter we can use the Expansion tile widget. It is quite easy and interesting.</p><p>So, now what is Expansion Tile? - A single line list tile with a trailing button that expands or collapses the tile to reveal or hide the children. Let’s start the coding part.</p><ul><li>First of all, create a new Flutter project and delete everything. Your main.dart will look like this:</li></ul><pre>import &#39;dart:ui&#39;;<br>import &#39;package:flutter/material.dart&#39;;</pre><pre>void main() {<br>  runApp(MyApp());<br>}</pre><pre>class MyApp extends StatelessWidget {<br>  // This widget is the root of your application.<br>  @override<br>  Widget build(BuildContext context) {<br>    return MaterialApp(<br>      title: &#39;Flutter Demo&#39;,<br>      debugShowCheckedModeBanner: false,<br>      theme: ThemeData(<br>        primarySwatch: Colors.<em>blue</em>,<br>        accentColor: Colors.<em>black</em>,<br>        visualDensity: VisualDensity.<em>adaptivePlatformDensity</em>,<br>      ),<br>      home: ExpansionTileDemo(),<br>    );<br>  }<br>}</pre><ul><li>Create a stateful widget named- ExpasionTileDemo.</li><li>Add the below code within your build method of ExpansionTileDemo class.</li></ul><pre>@override<br>Widget build(BuildContext context) {<br>  return Scaffold(<br>    appBar: AppBar(<br>      title: Text(&#39;ExpansionTile&#39;),<br>    ),<br>    body: Column(<br>      children: [<br>        Image.asset(<br>          &#39;assets/coffee.jpg&#39;,<br>          height: 150,<br>        ),<br>        Divider(<br>          height: 1,<br>          color: Colors.<em>grey</em>,<br>        ),<br>        ExpansionTile(<br>          backgroundColor: Colors.<em>yellow</em>[50],<br>          title: Text(<br>            &#39;Coffee&#39;,<br>            style: TextStyle(<br>              color: Colors.<em>black</em>,<br>              fontSize: 20,<br>            ),<br>            textAlign: TextAlign.center,<br>          ),<br>          children: [<br>            Padding(<br>              padding: const EdgeInsets.all(8.0),<br>              child: Text(<br>                &#39;Coffee is a brewed drink prepared from roasted coffee beans, the seeds of berries from certain Coffee species.&#39;,<br>                style: TextStyle(fontSize: 15),<br>                maxLines: 3,<br>                softWrap: true,<br>                textAlign: TextAlign.start,<br>              ),<br>            ),<br>          ],<br>        ),<br>      ],<br>    ),<br>  );<br>}</pre><p>I have created ExpansionTileDemo class and within the build method return scaffold.</p><p>I have added a column and within that added Image.asset and ExpansionTile widget.</p><p>Useful properties:-</p><ul><li>initiallyExpanded: specify whether the expansion tile will be expanded or collapsed. Default is false i.e. collapsed.</li><li>title: To give a title to your tile. This is the required attribute.</li><li>subtitle: Add additional information below the title.</li><li>expandedAlignment: To specify the alignment of the children.</li><li>trailing: Display widget after the title. By default, the rotating icon will be displayed.</li><li>leading: Display widget before the title.</li><li>children: Widget(s) to display when tile expanded.</li><li>onExpansionChanged: Define a function to perform changes when a tile expands or collapses.</li><li>backgroundColor: Display background color behind the sublist when expanded.</li></ul><p>So, we are done with the coding part, and let’s run the application to see the output.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/600/1*HeajAO7U4RHHhPbx36RTnA.gif" /></figure><p>By default, keyboard_arrow_down will be displayed as a trailing icon. But we can change the leading and trailing icon as per our requirement.</p><p>yay!! It is done.</p><p>Thank you for reading a blog, if you find it worthy don’t forget to clap 😛</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=a93699ec7366" width="1" height="1" alt=""><hr><p><a href="https://blog.nonstopio.com/expand-collapse-views-in-flutter-a93699ec7366">Expand/collapse views in Flutter</a> was originally published in <a href="https://blog.nonstopio.com/">nonstopio</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Add YouTube player to flutter app]]></title>
            <link>https://blog.nonstopio.com/add-youtube-player-to-flutter-app-51e822709225?source=rss-75331172b793------2</link>
            <guid isPermaLink="false">https://medium.com/p/51e822709225</guid>
            <category><![CDATA[flutter]]></category>
            <category><![CDATA[flutter-app-development]]></category>
            <category><![CDATA[mobile-apps]]></category>
            <category><![CDATA[youtube]]></category>
            <category><![CDATA[mobile-app-development]]></category>
            <dc:creator><![CDATA[Maitri Varia]]></dc:creator>
            <pubDate>Wed, 25 Nov 2020 12:40:28 GMT</pubDate>
            <atom:updated>2020-11-25T12:40:28.351Z</atom:updated>
            <content:encoded><![CDATA[<h3>Add YouTube player to your flutter app</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*AIej32AAN8IPjpYZzWilCg.png" /><figcaption>source: <a href="https://www.google.com/">www.google.com</a></figcaption></figure><p>hey folks, nowadays, Flutter is the fastest growing technology as well as skills amongst software engineers. So, today I will show you how to display YouTube videos in your Flutter application.</p><p>First of all, add the <a href="https://pub.dev/packages/youtube_player_flutter"><strong>youtube_player_flutter</strong></a><strong> </strong>plugin to your pubspecp.yaml file. Please check the latest version by clicking on the attached link. This plugin supports both Android and iOS platforms. No need to add an API key to a google account.</p><pre>youtube_player_flutter: <a href="https://pub.dev/packages/youtube_player_flutter"><strong>latest version</strong></a></pre><p>Once added, click on pub get or run command <strong>flutter pub get</strong> from the terminal.</p><p>Now, moving to the coding part.</p><pre>YoutubePlayer(<br>  controller: YoutubePlayerController(<br>    initialVideoId: &#39;zn2GwbPG-tc&#39;, //Add videoID.<br>    flags: YoutubePlayerFlags(<br>      hideControls: false,<br>      controlsVisibleAtStart: true,<br>      autoPlay: false,<br>      mute: false,<br>    ),<br>  ),<br>  showVideoProgressIndicator: true,<br>  progressIndicatorColor: AppColors.<em>primary</em>,<br>),</pre><p>First of all, add the YoutubePlayer widget to display video in your Flutter application.</p><ul><li>showVideoProgressIndicator - to true to display a progress bar at the time of buffering.</li><li>initialVideoId - add YouTube ID to display video. The plugin also provides a method to extract the video-id from the URL. code snippet available below.</li><li>progressIndicatorColor - set progress bar color as per matching with app’s theme.</li><li>controller - used to display custom controllers and also provide methods to add controls.</li><li>hideControls - To hide the controls when playing the videos. The default value is false which means by default controls will be displayed on the screen. If set to true controls will not be visible.</li><li>controlsVisibleAtStart - If set to true controls will be visible at the start of the video. The default value is false.</li></ul><p>Now, how to extract video ID from the whole YouTube URL? <strong>YoutubePlayer.convertUrlToId()</strong> method will return YouTube video ID from the given URL.</p><pre>try {<br>  String videoID= YoutubePlayer.<em>convertUrlToId</em>(videoURL);<br>  print(videoID);<br>} on Exception catch (exception) {<br>  print(exception);<br>  return &quot;&quot;;<br>} catch (error) {<br>  print(error);<br>  return &quot;&quot;;<br>}</pre><p>Let’s run the app and see the output.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*QkBD8omBpfD3i-8a6b0W-Q.png" /></figure><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=51e822709225" width="1" height="1" alt=""><hr><p><a href="https://blog.nonstopio.com/add-youtube-player-to-flutter-app-51e822709225">Add YouTube player to flutter app</a> was originally published in <a href="https://blog.nonstopio.com/">nonstopio</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[How to isolate API call]]></title>
            <link>https://blog.nonstopio.com/how-to-isolate-api-call-f576add9715?source=rss-75331172b793------2</link>
            <guid isPermaLink="false">https://medium.com/p/f576add9715</guid>
            <category><![CDATA[volley]]></category>
            <category><![CDATA[mobile-apps]]></category>
            <category><![CDATA[mobile-app-development]]></category>
            <category><![CDATA[android]]></category>
            <category><![CDATA[api-integration]]></category>
            <dc:creator><![CDATA[Maitri Varia]]></dc:creator>
            <pubDate>Tue, 25 Aug 2020 07:28:46 GMT</pubDate>
            <atom:updated>2020-08-25T07:28:46.880Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/800/1*hHJj4NluA0LATpek5rH1mQ.jpeg" /></figure><h3>How to isolate Volley API call</h3><p>Hey folks, I am coming with another interesting blog and that is<em> how to isolate API calls from the Activity. </em>I have used Google’s <a href="https://developer.android.com/training/volley">Volley</a> library for demonstration.</p><p><strong><em>Benefits to isolate API calls from Activity.</em></strong></p><p>1. Easy to maintain.<br>2. No code boilerplate.<br>3. Make API error handling easy.</p><p><strong><em>How to structure the code:-</em></strong><br>1. Create a different class to execute API calls. (NetworkController.java)<br>2. Create an interface to handle the API response. (APICallBackListener.java)<br>3. Make an API call from the Activity. (MainActivity.java)</p><p>First of all, create a different package called <strong>“APIService” </strong>and add NetworkController.java and APICallBackListener.java files.</p><p>Add the below code to your NetworkController.java file.</p><pre>public class NetworkController {<br><br>    private APICallBackListener mResultCallback = null;<br>    private Context mContext;<br>    private ProgressDialog progressDialog;<br>    private String TAG = &quot;API response&quot;;<br><br>    public NetworkController(APICallBackListener resultCallback, Context context) {<br><br>        mResultCallback = resultCallback;<br>        mContext = context;<br>    }<br><br><br>    public void fetchPOSTAPIData(String url, final Map&lt;String, String&gt; params,boolean isShowProgressDialog) {<br><br>        try {<br><br>            if (isShowProgressDialog) {<br>                initProgressDialog();<br>                showProgressDialog();<br>            }<br><br>            RequestQueue queue = Volley.<em>newRequestQueue</em>(mContext);<br><br>            StringRequest postRequest = new StringRequest(Request.Method.<em>POST</em>, url,<br>                    new Response.Listener&lt;String&gt;() {<br><br>                        @Override<br>                        public void onResponse(String response) {<br>                            // API response<br>                            Log.<em>e</em>(TAG, response);<br>                            if (mResultCallback != null) {                                                      mResultCallback.notifySuccess(response);<br>                            }<br>                            hideProgressDialog();<br>                        }<br>                    },<br>                    new Response.ErrorListener() {<br><br>                        @Override<br>                        public void onErrorResponse(VolleyError error) {<br>                            // error<br>                            Log.<em>e</em>(TAG,                              error.networkResponse.toString());<br>                            if (mResultCallback != null)<br>                                mResultCallback.notifyError(error);<br>                            hideProgressDialog();<br>                        }<br>                    }<br>            ) {<br><br>                @Override<br>                protected Map&lt;String, String&gt; getParams() {<br><br>                    return params;<br>                }<br>            };<br>            queue.add(postRequest);<br><br>        } catch (Exception e) {<br>            e.printStackTrace();<br>        }<br>    }<br><br>    public void fetchGETAPIData(String url, boolean  isShowProgressDialog) {<br><br>        try {<br><br>            if (isShowProgressDialog) {<br>                initProgressDialog();<br>                showProgressDialog();<br>            }<br><br>            RequestQueue queue = Volley.<em>newRequestQueue</em>(mContext);<br><br>            StringRequest stringRequest = new StringRequest(Request.Method.<em>GET</em>,url, new Response.Listener&lt;String&gt;() {<br><br>                @Override<br>                public void onResponse(String response) {<br><br>                    Log.<em>e</em>(TAG, response);<br>                    if (mResultCallback != null)<br>                        mResultCallback.notifySuccess(response);<br>                    hideProgressDialog();<br>                }<br>            }, new Response.ErrorListener() {<br><br>                @Override<br>                public void onErrorResponse(VolleyError error) {<br><br>                    Log.<em>e</em>(TAG,<br>                            error.networkResponse.toString());<br>                    if (mResultCallback != null)<br>                        mResultCallback.notifyError(error);<br>                    hideProgressDialog();<br>                }<br>            });<br>            queue.add(stringRequest);<br>        } catch (Exception e) {<br>            e.printStackTrace();<br>        }<br>    }<br><br>    private void initProgressDialog() {<br><br>        progressDialog = new ProgressDialog(mContext);<br>        progressDialog.setTitle(&quot;Fetching data&quot;);<br>        progressDialog.setMessage(&quot;Please wait&quot;);<br>        progressDialog.setCancelable(false);<br>    }<br><br>    private void showProgressDialog() {<br><br>        if (progressDialog != null) {<br>            if (!progressDialog.isShowing())<br>                progressDialog.show();<br>        } else<br>            initProgressDialog();<br>    }<br><br>    private void hideProgressDialog() {<br><br>        if (progressDialog != null) {<br>            if (progressDialog.isShowing())<br>                progressDialog.dismiss();<br>        }<br>    }<br>}</pre><ul><li>fetchGETAPIData() — This method is used to make GET API calls using Volley.</li><li>fetchPOSTAPIData() — This method is used to make POST API calls using volley. Pass parameters from the activity class.</li></ul><p>Now, add the below code to your APICallBackListener.java file.</p><pre>public interface APICallBackListener {<br><br>    void notifySuccess(String response);<br><br>    void notifyError(VolleyError error);<br>}</pre><p>At last call API from the MainActivity.java file.</p><pre>public class MainActivity extends AppCompatActivity {</pre><pre>private Context context;<br>private Button btnSubmit;<br>APICallBackListener callBackListener;<br>NetworkController networkManager;</pre><pre>@Override<br>protected void onCreate(Bundle savedInstanceState) {<br><br>    super.onCreate(savedInstanceState);<br>    setContentView(R.layout.<em>activity_main</em>);<br>    context = this;<br><br>    initControls();<br>    initCallBack();<br>}</pre><pre>private void initCallBack() {<br><br>    callBackListener = new APICallBackListener() {<br><br>        @Override<br>        public void notifySuccess(String response) {<br><br>            Toast.<em>makeText</em>(context, &quot;API call success&quot;, Toast.<em>LENGTH_SHORT</em>).show();<br>            /*Add your stuff here */<br>         }<br><br>        @Override<br>        public void notifyError(VolleyError error) {<br><br>            Toast.<em>makeText</em>(context, &quot;API call Failed&quot;, Toast.<em>LENGTH_SHORT</em>).show();<br>            /*Add your stuff here */<br>        }<br>    };<br>}</pre><pre>private void initControls() {<br> <br>     btnSubmit = findViewById(R.id.<em>btnSubmit</em>);<br>     btnSubmit.setOnClickListener(new View.OnClickListener() {<br><br>    @Override<br>    public void onClick(View v) {<br><br>        String url=&quot;https://randomuser.me/api/0.4/?randomapi&quot;;<br>        networkManager.fetchGETAPIData(url, true);<br>    }<br>});<br>}}</pre><p>Now, how to make POST request:- <br>- Create a parameter list and pass it as an argument to the fetchPOSTAPIData() method.</p><pre>@Override<br>    public void onClick(View v) {<br><br>    String url = &quot;<a href="http://httpbin.org/post">http://httpbin.org/post</a>&quot;;<br><br>   Map&lt;String, String&gt;  params = new HashMap&lt;String, String&gt;();</pre><pre>   params.put(&quot;name&quot;, &quot;XYZ&quot;);<br>   params.put(&quot;domain&quot;, &quot;<a href="http://itsalif.info/">http://xyz.info</a>&quot;);<br>   networkManager.fetchPOSTAPIData(url, params, true);<br> }</pre><p>Woah!!! we are done with the code. Now, run and test the application.</p><p>If you find worth reading this blog, don’t forget to clap<strong> 😉</strong></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=f576add9715" width="1" height="1" alt=""><hr><p><a href="https://blog.nonstopio.com/how-to-isolate-api-call-f576add9715">How to isolate API call</a> was originally published in <a href="https://blog.nonstopio.com/">nonstopio</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[What is new in Android 11]]></title>
            <link>https://blog.nonstopio.com/what-is-new-in-android-11-1b14bd0b1277?source=rss-75331172b793------2</link>
            <guid isPermaLink="false">https://medium.com/p/1b14bd0b1277</guid>
            <category><![CDATA[android-app-development]]></category>
            <category><![CDATA[software-development]]></category>
            <category><![CDATA[android-11]]></category>
            <category><![CDATA[mobile-app-development]]></category>
            <category><![CDATA[android]]></category>
            <dc:creator><![CDATA[Maitri Varia]]></dc:creator>
            <pubDate>Tue, 11 Aug 2020 04:27:02 GMT</pubDate>
            <atom:updated>2020-08-11T04:27:02.084Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*tGWldykcB9GZ9HGlg1nUdw.jpeg" /></figure><p>Android 11 Beta is released and available for developers for review, implementation, and testing. Google has released a developer program named- <a href="https://developer.android.com/11weeksofandroid">#11 weeks of an Android</a>. Android 11 was launched in February 2020 and will lunch a stable version hopefully in September 2020. Android 11 has been launched with API level 30.</p><p><strong>Below is the list of the features of Android 11-</strong></p><ul><li><strong><em>One-time permission:-</em></strong><em> </em>User can grant temporary permission.</li><li><strong><em>A permission dialog visibility:-</em></strong><em> </em>Android 11 onward only <strong>“<em>doesn’t ask again” </em></strong>action will be implied if the user denies the same permission multiple times in a single application. “<strong>Only this time</strong>” refers to, you get permission approval for that particular session time, that means that if the app is in the foreground. If we select only this time then next time when the user launches the application, permission dialog will appear.</li><li>Multiple deny will be considered as deny and don’t ask again. An app will not throw the permission dialog next time onward.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/976/1*wJY8-Z1el07sWqtVDl2VrQ.png" /><figcaption>source: https://google.com</figcaption></figure><ul><li><strong><em>Reset app permission :-</em></strong> If a user does not interact with the application for a longer time then from an Android 11, application permission will be reset for all the sensitive permissions like Camera, Location, and Microphone.</li><li><strong><em>Background location access :-</em></strong><em> </em>If your app target and runs on the Android 11 device then the user will not able to see system dialog which includes a button to enable background service. The developer needs to add <strong>“Allow all the time” </strong>option when asking for permission. And also navigate the user to the settings page.</li><li><strong><em>Package visibility:-</em></strong><em> </em>Apps that target Android 11 and wants to interact with other installed app, a developer needs to add <strong>&lt;queries&gt; </strong>element in androidManifest.xml.</li><li>Android 11 has come up with Device control added in the <strong>Power menu</strong>.</li><li>Media Controls also are added in the <strong>quick settings</strong>. Users can start the previous session from the carousel without starting the app.</li></ul><figure><img alt="Example of quick settings for music." src="https://cdn-images-1.medium.com/max/600/1*u9eTY1NIAUHeNco4O7-CTA.jpeg" /><figcaption>source: https://google.com</figcaption></figure><ul><li>Android 11 has also camp up with great conversation experiences like <strong>“<em>Chat bubbles” </em></strong><em>— </em>Bubbles are now available to developers to surface the conversation across the system.</li></ul><figure><img alt="Example for chat bubble look on the device." src="https://cdn-images-1.medium.com/max/400/1*rltov0vP5ZXMmXaDGMtM0g.png" /><figcaption>Source: https://google.com</figcaption></figure><ul><li>Users can see various 5G icons using permissio - <strong>READ_PHONE_STATE.<br></strong>LTE, LTE with career aggregation, advanced pro-LTE (5Ge), NR(5G), NR on millimeter-wave cellular bands(5G+).</li><li><strong>Good news for developers:-</strong> Android 11 supports wireless debugging. To use wireless debug, you need to pair your device with the workstation using a pairing code. Make sure the device and the work station must be in the same wireless network.</li><li><strong>READ_PHONE_NUMBERS</strong>:- If your application target Android 11, to read the phone numbers from the device then update your permission from READ_PHONE-STATE to READ_PHONE_NUMBERS.</li><li><strong><em>Native screen recording:-</em></strong><em> </em>Android 11 lunch pretty much confirms that the screen recording feature will be launched.</li><li><strong><em>Notification history:-</em></strong><em> </em>Android 11 onward user can see the dismissed notification from the notification tray.</li><li>Previously, turning on an Airplane mode will turn off the Bluetooth which doesn’t make sense. So, from Android 11 launch Bluetooth stays on when Airplane mode is activated.</li><li><strong><em>ADB incremental installation:-</em></strong><em> </em>Installing large apps (2GB or larger) using ADB can be a slow process. Developers can run the application using ADB 10x faster than previously. This feature only available for Android 11 devices.</li></ul><p>That’s all about Android 11, if you liked the blog then don’t forget to clap ;-)</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=1b14bd0b1277" width="1" height="1" alt=""><hr><p><a href="https://blog.nonstopio.com/what-is-new-in-android-11-1b14bd0b1277">What is new in Android 11</a> was originally published in <a href="https://blog.nonstopio.com/">nonstopio</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[OTP(One Time Passcode) authentication using Firebase]]></title>
            <link>https://blog.nonstopio.com/otp-one-time-passcode-authentication-using-firebase-10b0111aba8a?source=rss-75331172b793------2</link>
            <guid isPermaLink="false">https://medium.com/p/10b0111aba8a</guid>
            <category><![CDATA[mobile-app-development]]></category>
            <category><![CDATA[android]]></category>
            <category><![CDATA[firebase]]></category>
            <category><![CDATA[authentication]]></category>
            <category><![CDATA[software-development]]></category>
            <dc:creator><![CDATA[Maitri Varia]]></dc:creator>
            <pubDate>Mon, 08 Jun 2020 11:47:06 GMT</pubDate>
            <atom:updated>2020-06-08T11:47:06.435Z</atom:updated>
            <content:encoded><![CDATA[<p>Hello People,</p><p>Google Firebase provides so many services like Firebase messaging(notification), Crashlytics, analytics, realtime database, remote config and many more<br>FYI- (<a href="https://firebase.google.com/docs/android/setup#available-libraries">https://firebase.google.com/docs/android/setup#available-libraries</a>).</p><p>Among all of them, I am going to demonstrate about <strong>Firebase</strong> <strong>Authentication. </strong>Firebase authenticates the user by sending One Time Password (OTP) via SMS to their phones.<strong><br></strong>The below image is useful to understand the process of <strong>Firebase Authentication.</strong></p><p><strong>How Firebase authentication works:-</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/978/1*pW1jxwTUiRusTdiefbXTLg.png" /><figcaption>(source:https://www.google.com)</figcaption></figure><p><strong>Steps to implement Firebase Authentication:-</strong></p><ol><li>Add your project to Firebase. (See the previous blog)</li><li>In your project level <strong>build.gradle</strong> file, add google’s maven repository in both <strong>buildscript</strong> and <strong>allproject</strong> section.</li><li>In your app level <strong>build.gradle </strong>file, add Firebase authentication library.</li></ol><pre>implementation &#39;com.google.firebase:firebase-auth:19.2.0&#39;</pre><p>Now, in Firebase console enable “Phone sign-in method” from Authentication.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*uY_hNyscdDrx0fOXK3TvXg.png" /></figure><p>Design your layout to get a user mobile number for Authentication.</p><pre>&lt;?xml version=&quot;1.0&quot; encoding=&quot;utf-8&quot;?&gt;<br>&lt;LinearLayout xmlns:android=&quot;http://schemas.android.com/apk/res/android&quot;<br>    android:layout_width=&quot;match_parent&quot;<br>    android:layout_height=&quot;match_parent&quot;<br>    android:focusableInTouchMode=&quot;true&quot;<br>    android:orientation=&quot;vertical&quot;&gt;<br><br>    &lt;TextView<br>        android:layout_width=&quot;match_parent&quot;<br>        android:layout_height=&quot;wrap_content&quot;<br>        android:background=&quot;@android:color/white&quot;<br>        android:gravity=&quot;center&quot;<br>        android:padding=&quot;10dp&quot;<br>        android:text=&quot;OTP Verification&quot;<br>        android:textColor=&quot;@android:color/white&quot;<br>        android:textSize=&quot;25dp&quot;<br>        android:textStyle=&quot;normal|bold&quot; /&gt;<br><br>    &lt;LinearLayout<br>        android:layout_width=&quot;match_parent&quot;<br>        android:layout_height=&quot;wrap_content&quot;<br>        android:layout_marginTop=&quot;20dp&quot;<br>        android:orientation=&quot;vertical&quot;&gt;<br><br>        &lt;LinearLayout<br>            android:layout_width=&quot;match_parent&quot;<br>            android:layout_height=&quot;wrap_content&quot;<br>            android:layout_marginLeft=&quot;15dp&quot;<br>            android:layout_marginTop=&quot;20dp&quot;<br>            android:layout_marginRight=&quot;15dp&quot;<br>            android:orientation=&quot;horizontal&quot;&gt;<br><br>            &lt;TextView<br>                android:layout_width=&quot;0dp&quot;<br>                android:layout_height=&quot;wrap_content&quot;<br>                android:layout_weight=&quot;1.2&quot;<br>                android:text=&quot;Please enter Mobile Number:-&quot;<br>                android:textColor=&quot;@android:color/black&quot; /&gt;<br><br>            &lt;EditText<br>                android:id=&quot;@+id/txtEnterMobileNumber&quot;<br>                android:layout_width=&quot;0dp&quot;<br>                android:layout_height=&quot;wrap_content&quot;<br>                android:layout_weight=&quot;0.9&quot;<br>                android:text=&quot;+91-9016285745&quot;<br>                android:inputType=&quot;numberDecimal&quot;<br>                android:maxLength=&quot;15&quot;<br>                android:textColor=&quot;@android:color/black&quot;<br>                android:textColorHint=&quot;@android:color/black&quot; /&gt;<br><br>        &lt;/LinearLayout&gt;<br><br>        &lt;LinearLayout<br>            android:layout_width=&quot;match_parent&quot;<br>            android:layout_height=&quot;wrap_content&quot;<br>            android:layout_marginLeft=&quot;15dp&quot;<br>            android:layout_marginRight=&quot;15dp&quot;&gt;<br><br>            &lt;TextView<br>                android:layout_width=&quot;0dp&quot;<br>                android:layout_height=&quot;wrap_content&quot;<br>                android:layout_weight=&quot;1.1&quot;<br>                android:text=&quot;Please enter OTP:-&quot;<br>                android:textColor=&quot;@android:color/black&quot; /&gt;<br><br>            &lt;EditText<br>                android:id=&quot;@+id/txtOTP&quot;<br>                android:layout_width=&quot;0dp&quot;<br>                android:layout_height=&quot;wrap_content&quot;<br>                android:layout_weight=&quot;0.9&quot;<br>                android:inputType=&quot;numberDecimal&quot;<br>                android:maxLength=&quot;6&quot;<br>                android:text=&quot;543221&quot;<br>                android:textColor=&quot;@android:color/black&quot;<br>                android:textColorHint=&quot;@android:color/black&quot; /&gt;<br><br>        &lt;/LinearLayout&gt;<br><br>    &lt;/LinearLayout&gt;<br><br>    &lt;Button<br>        android:id=&quot;@+id/btnSubmit&quot;<br>        android:layout_width=&quot;match_parent&quot;<br>        android:layout_height=&quot;wrap_content&quot;<br>        android:layout_margin=&quot;20dp&quot;<br>        android:background=&quot;@android:color/holo_blue_dark&quot;<br>        android:text=&quot;Submit&quot;<br>        android:textAllCaps=&quot;false&quot;<br>        android:textColor=&quot;@android:color/white&quot;<br>        android:textStyle=&quot;bold&quot; /&gt;<br>&lt;/LinearLayout&gt;</pre><p>Once the user enters the mobile number, you need to verify that number by sending an SMS to that phone number. Use verifyPhoneNumber() method of Firebase SDK along with the OnVerificationStateChangedCallbacks.</p><pre>PhoneAuthProvider.<em>getInstance</em>().verifyPhoneNumber(<br>        &quot;+91&quot; + mobileNumber,<br>        10,<br>        TimeUnit.<em>SECONDS</em>,<br>        TaskExecutors.<em>MAIN_THREAD</em>,<br>        mCallBacks //Object of OnVerificationStateChangedCallbacks<br>);</pre><p>OnVerificationStateChangedCallbacks has 4 methods that need to be implemented in the code.</p><ol><li><strong>onVerificationCompleted</strong> — This method can be called in 2 situations.<br> a. Instant verification — In some cases, no phone number can be verified without sending or entering the phone number.<br> b. Auto retrieval — Google play services automatically detect incoming messages and perform verification without user interaction.</li><li><strong>onVerificationFailed </strong>— This method invoked when the request is invalid. For ex: either mobile number or verification code is not correct.</li><li><strong>onCodeSent </strong>— This method invoked when OTP(Verification code) sent to the provided mobile number. Also, a verficationID will be provided for further uses.</li><li><strong>onCodeAutoRetrievalTimeOut </strong>— This method invoked when the time exceeds the specified timeout in verifyPhoneNumber method without completing the verification process. This method is optional.</li></ol><p>Let’s see the callback implementation.</p><pre>mCallBacks = new PhoneAuthProvider.OnVerificationStateChangedCallbacks() {<br>        @Override<br>        public void onVerificationCompleted(PhoneAuthCredential phoneAuthCredential) {<br>            Toast.<em>makeText</em>(context, &quot;Verification completed&quot;, Toast.<em>LENGTH_SHORT</em>).show();<br>        }</pre><pre>        @Override<br>        public void onVerificationFailed(FirebaseException e) {<br>            Toast.<em>makeText</em>(context, &quot;Verification failed.&quot;, Toast.<em>LENGTH_SHORT</em>).show();<br>        }</pre><pre>        @Override<br>        public void onCodeSent(String s, PhoneAuthProvider.ForceResendingToken forceResendingToken) {<br>            super.onCodeSent(s, forceResendingToken);<br>           Toast.<em>makeText</em>(FirebasePhoneActivity.this, &quot;Code has Sent to given mobile number.&quot;, Toast.<em>LENGTH_SHORT</em>).show();</pre><pre>        }<br></pre><pre>        @Override<br>        public void onCodeAutoRetrievalTimeOut(String s) {<br>            super.onCodeAutoRetrievalTimeOut(s);<br>          <br>        }<br>    };</pre><p>After the user enters the verification code, create an object of PhoneAuthCredential and pass the OTP and verification ID-generated using onCodeSent() method as params.</p><pre>PhoneAuthCredential credential = PhoneAuthProvider.<em>getCredential</em>(verificationId, otp);</pre><p>Now, complete the sign in process using the FirebaseAuth.signInWithCredential() method.</p><pre>private void signInWithPhoneAuthCredential(PhoneAuthCredential credential) {</pre><pre>    mAuth.signInWithCredential(credential)<br>            .addOnCompleteListener(OTPScreen.this, new OnCompleteListener&lt;AuthResult&gt;() {<br>                @Override<br>                public void onComplete(@NonNull Task&lt;AuthResult&gt; task) {<br>                    if (task.isSuccessful()) {<br>                        Toast.<em>makeText</em>(context, &quot;Signed in successfully&quot;, Toast.<em>LENGTH_SHORT</em>).show();<br>                    } else {</pre><pre>                        Toast.<em>makeText</em>(context, &quot;Signed in unsuccessfull&quot;, Toast.<em>LENGTH_SHORT</em>).show();<br>                    }<br>                }<br>            });<br>}</pre><p>Hurrah, we are done with the code, run the code, and test the application.</p><p>Test the code with whitelisted phone numbers:-</p><p>Why:-</p><p>Firebase enforces a limit on the number of SMS sent to a single mobile number within a limited period. And if you exceed the limit verification request might be restricted. If you find this problem during the development, whitelist the phone number from the Firebase console.</p><p>How to whitelist the phone numbers:-</p><ol><li>In the Firebase console, open the authentication section.</li><li>In the sign-in method, the tab enables the phone provider.</li><li>Provide the phone number you want to use during the development with the default verification code.</li><li>Save the form.</li></ol><figure><img alt="" src="https://cdn-images-1.medium.com/max/846/1*FWL86ltos0OI9ENji0hZCQ.png" /></figure><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=10b0111aba8a" width="1" height="1" alt=""><hr><p><a href="https://blog.nonstopio.com/otp-one-time-passcode-authentication-using-firebase-10b0111aba8a">OTP(One Time Passcode) authentication using Firebase</a> was originally published in <a href="https://blog.nonstopio.com/">nonstopio</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[An Introduction to Android ROOM]]></title>
            <link>https://blog.nonstopio.com/an-introduction-to-android-room-e403b5c8ce43?source=rss-75331172b793------2</link>
            <guid isPermaLink="false">https://medium.com/p/e403b5c8ce43</guid>
            <category><![CDATA[object-relational-mapping]]></category>
            <category><![CDATA[mobile-app-development]]></category>
            <category><![CDATA[android]]></category>
            <category><![CDATA[android-orm]]></category>
            <dc:creator><![CDATA[Maitri Varia]]></dc:creator>
            <pubDate>Thu, 23 May 2019 06:34:52 GMT</pubDate>
            <atom:updated>2019-05-23T06:34:52.326Z</atom:updated>
            <content:encoded><![CDATA[<p>Android ROOM is an abstraction layer over SQLite.An Android ROOM introduced in Google I/O 2017. Android ROOM implements ORM (Object — Relational Mapping) to store data.</p><p><strong>So, What is ORM?</strong></p><blockquote>Object-relational mapping (ORM, O/RM, and O/R mapping) is a programming technique for converting data between incompatible type systems in relational databases and object-oriented programming languages. This creates, in effect, a “virtual object database” that can be used from within the programming language.</blockquote><blockquote>Wikipedia reference:-</blockquote><p>ORM reduces the amount of code that needs to be written to perform database operations.</p><p>To implement ORM in an Android, following are the famous libraries available.<br>1) Sugar ORM<br>2) GreenDAO<br>3) Realm<br>4) ORM Lite<br>5) ROOM.</p><p><strong>Advantages of an Android ROOM:-</strong></p><ul><li>ROOM provides compile-time verification of SQL Queries.</li><li>ROOM will update SQL queries as schema changes.</li><li>ROOM will work with LiveData and RxJava.</li></ul><p><strong>How Android ROOM works:-</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ZR5rh9NNp3yiw8PcfXkg9A.png" /><figcaption>Ref-https://www.google.com</figcaption></figure><p><strong><em>Steps to implement an Android ROOM in your project:-</em></strong></p><p><strong><em>1. Add a dependency in your build.gradle file.</em></strong></p><pre>implementation &quot;android.arch.persistence.room:runtime:$1.1.1&quot;<br>annotationProcessor &quot;android.arch.persistence.room:compiler:$1.1.1&quot;</pre><p><strong>2.</strong> <strong><em>Create Entities (Tables in SQLite) using @Entity annotation. Also create its getter(s) &amp; setter(s).</em></strong></p><pre>@Entity<br>public class Employee implements Serializable {<br><br>    @PrimaryKey(autoGenerate = true)<br>    private int id;</pre><pre>    @ColumnInfo(name = &quot;employeeName&quot;)<br>    private String employeeName;<br><br>    public int getId() {<br>        return id;<br>    }<br><br>    public void setId(int id) {<br>        this.id = id;<br>    }<br><br>    public String getEmployeeName() {<br>        return task;<br>    }<br><br>    public void setEmployeeName(String employeeName) {<br>        this.employeeName = employeeName;<br>    }<br>}</pre><p><strong>3. Create DAOs (Data Access Object) using interface.</strong></p><pre>@Dao<br>public interface EmployeeDAO {<br><br>    @Query(&quot;SELECT * FROM employee&quot;)<br>    List&lt;Employee&gt; getAllEmployee();<br><br>    @Insert<br>    void insert(Employee employee);<br>}</pre><p><strong><em>4. Create database.</em></strong></p><pre>@Database(entities = {Employee.class}, version = 1)<br>public abstract class AppDatabase extends RoomDatabase {<br><br>    private static AppDatabase <em>INSTANCE</em>;<br><br>    public static AppDatabase getAppDatabase(Context context) {<br><br>    Log.<em>e</em>(&quot;DATABASE&quot;, &quot;getAppDatabase DATABASE_NAME: &quot; + &quot;temp.db&quot;);<br><br>        <em>INSTANCE </em>=<br>                Room.<em>databaseBuilder</em>(context.getApplicationContext(),<br>                        AppDatabase.class, &quot;temp.db&quot;)<br>                        .allowMainThreadQueries()<br>                        .fallbackToDestructiveMigration()<br>                        .build();<br>        return <em>INSTANCE</em>;<br>    }<br><br>    public abstract TaskDao employeeDao();<br>}</pre><p><strong><em>5. Create Database client.</em></strong></p><pre>public class DatabaseClient {<br><br>    private Context context;<br>    private static DatabaseClient <em>databaseClient</em>;<br><br>    private AppDatabase database;<br><br>    public DatabaseClient(Context context) {<br>        this.context = context;<br>        this.database = Room.<em>databaseBuilder</em>(context,AppDatabase.class,&quot;MyToDos&quot;).build();<br>    }<br><br>    public static synchronized DatabaseClient getInstance(Context ctx){<br>        if (<em>databaseClient</em>==null)<br>            <em>databaseClient</em>=new DatabaseClient(ctx);<br>        return <em>databaseClient</em>;<br>    }<br><br>    public AppDatabase getAppDatabase(){<br>        return database;<br>    }<br>}</pre><p>6. <strong><em>Now, how to insert &amp; retrieve data in the database.</em></strong></p><p>In EmployeeActivity file, create objects of Appdatabase and AndroidRoomApplication.</p><pre>AppDatabase appDatabase;<br>AndroidRoomApplication application;</pre><pre>appDatabase = AppDatabase.<em>getAppDatabase</em>(context);<br>application = new AndroidRoomApplication();</pre><ul><li><strong><em>Inserting Employee details in the database.</em></strong></li></ul><pre>Employee employee=new Employee();<br>employee.setEmployeeName(&quot;ABC&quot;);<br>appDatabase.employeeDao().insert(employee);</pre><ul><li><strong><em>Fetch employee data from the database.</em></strong></li></ul><pre>List&lt;Employee&gt; employeeList=new ArrayList&lt;&gt;();<br>employeeList=appDatabase.employeeDao().getAllEmployee();</pre><p>Now, retrieve data of each employee from <strong>employeeList</strong> using loop or iterator.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=e403b5c8ce43" width="1" height="1" alt=""><hr><p><a href="https://blog.nonstopio.com/an-introduction-to-android-room-e403b5c8ce43">An Introduction to Android ROOM</a> was originally published in <a href="https://blog.nonstopio.com/">nonstopio</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
    </channel>
</rss>