<?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 Mahesh Vhatkar on Medium]]></title>
        <description><![CDATA[Stories by Mahesh Vhatkar on Medium]]></description>
        <link>https://medium.com/@maheshvhatkar82?source=rss-4ea6661e33b4------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*DTC8rQHDsNiVfsWgZQlgSg.jpeg</url>
            <title>Stories by Mahesh Vhatkar on Medium</title>
            <link>https://medium.com/@maheshvhatkar82?source=rss-4ea6661e33b4------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sun, 06 Dec 2026 11:30:12 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@maheshvhatkar82/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[Latest Most Frequently asked Android Developer Interview Questions part II]]></title>
            <link>https://medium.com/@maheshvhatkar82/latest-most-frequently-asked-android-developer-interview-questions-part-ii-c3c43cc2e5a7?source=rss-4ea6661e33b4------2</link>
            <guid isPermaLink="false">https://medium.com/p/c3c43cc2e5a7</guid>
            <category><![CDATA[interview-questions]]></category>
            <category><![CDATA[android-development]]></category>
            <dc:creator><![CDATA[Mahesh Vhatkar]]></dc:creator>
            <pubDate>Mon, 10 Nov 2025 10:45:21 GMT</pubDate>
            <atom:updated>2025-11-10T15:31:08.372Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*qfDH811Uyl5GJ8xZH86Bjw.png" /></figure><p>This is the second part of our <strong><em>Latest Most Frequently asked Android Developer Interview Questions.</em></strong></p><p>Lets continue with next question set of easy level.</p><blockquote>🟢<strong>Easy Level 2 </strong>:-</blockquote><h3>1. What is the difference between val and var in Kotlin?</h3><p>In Kotlin, val is used to declare a <strong>read-only (immutable)</strong> variable whose value cannot be reassigned once initialized, similar to a final variable in Java. On the other hand, var is used for <strong>mutable variables</strong>, meaning their values can be reassigned at runtime. Both val and var must be initialized before use.</p><h3>2. What is the difference between val and const val in Kotlin?</h3><p>Both are used for immutable values, but const val is a <strong>compile-time constant</strong>, meaning its value must be known at compile time and can only be used at the top level or inside objects/companion objects.<br> val is a <strong>runtime constant</strong>, initialized when the object is created. Example: const val APP_NAME = &quot;My App&quot; vs val date = Date().</p><h3>3. What is lateinit and lazy in Kotlin?</h3><p>lateinit is used with <strong>mutable (</strong><strong>var) non-null variables</strong> that are initialized later, not during declaration — commonly used for dependency injection or view binding. lazy is used with <strong>immutable (</strong><strong>val) variables</strong>, and its initialization happens only once when the variable is accessed for the first time. It is also <strong>thread-safe</strong> by default.</p><h3>4. What are scope functions in Kotlin?</h3><p>Scope functions allow us to execute a block of code in the context of an object, reducing boilerplate. They are: let, run, also, apply, and with.<br> Each differs slightly in return type and the way it refers to the context object (this or it). Example: apply modifies the object, while let is often used for null checks.</p><h3>5. What is an Intent Filter in Android?</h3><p>Intent filters in Android are declarations in the manifest file that specify the types of intents an activity, service, or broadcast receiver can respond to. They allow the system to determine which component can handle a given intent based on the action, data, and category specified. They enable features like opening links in specific apps or sharing content between apps. Without intent filters, a component can only be started explicitly by its exact class name.</p><h3>6. What is the MVVM architecture in Android?</h3><p>MVVM stands for <strong>Model–View–ViewModel</strong>. The <strong>Model</strong> handles data and business logic, the <strong>View</strong> displays data on the UI, and the <strong>ViewModel</strong> connects the two — exposing data through LiveData or StateFlow. This structure improves testability, code reusability, and separation of concerns.</p><h3>7. What are the OOPs concepts?</h3><p>The four main Object-Oriented Programming concepts are <strong>Encapsulation, Inheritance, Polymorphism, and Abstraction</strong>. They help in organizing code, improving reusability, and maintaining scalability by representing real-world entities as objects.</p><h3>8. Explain each OOPs concept briefly.</h3><p><strong>Encapsulation</strong> — Binding data and methods together while restricting direct access to internal details.<br> <strong>Inheritance</strong> — Allowing a class to acquire properties and behavior from another class.<br> <strong>Polymorphism</strong> — Performing a single action in different ways, such as method overloading or overriding.<br> <strong>Abstraction</strong> — Hiding implementation details and exposing only the essential functionality.</p><h3>9. What are the launch modes in Android?</h3><p>Launch modes in Android define how a new instance of an activity is created and managed in the task stack. <strong>Standard</strong> creates a new instance every time the activity is launched. <strong>SingleTop</strong> reuses the existing instance if it’s already on top of the stack. <strong>SingleTask</strong> creates only one instance in a separate task, clearing other activities on top if it already exists. <strong>SingleInstance</strong> ensures the activity runs in its own separate task and is not shared with any other activities.</p><h3>10. What is difference between singleTop and SingleTask?</h3><p>In <strong>singleTop</strong>, if an instance of the activity already exists at the top of the task stack, it is reused and the onNewIntent() method is called instead of creating a new instance. If it’s not on top, a new instance is created. In <strong>singleTask</strong>, there can be only one instance of the activity in the entire system; if it already exists in a task, that task is brought to the foreground, and all activities above it are cleared before calling onNewIntent().</p><p>These were the <strong>next 10 Easy-Level Android Interview Questions (Part 2)</strong>. Each answer is short yet conceptually strong — perfect for quick revision before interviews. Let me know if you have any suggestions.</p><p>Thank you for reading till the end. Stay tuned and keep learning! 💪<br> #AndroidDevelopment #InterviewPreparation #Kotlin #AndroidInterview #MobileDevelopment #LearnAndroid</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=c3c43cc2e5a7" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Latest Most Frequently asked Android Developer Interview Questions]]></title>
            <link>https://medium.com/@maheshvhatkar82/latest-most-frequently-asked-android-developer-interview-questions-5de8cd8a4507?source=rss-4ea6661e33b4------2</link>
            <guid isPermaLink="false">https://medium.com/p/5de8cd8a4507</guid>
            <category><![CDATA[android]]></category>
            <category><![CDATA[android-developers]]></category>
            <category><![CDATA[interview-questions]]></category>
            <dc:creator><![CDATA[Mahesh Vhatkar]]></dc:creator>
            <pubDate>Sat, 01 Nov 2025 11:12:34 GMT</pubDate>
            <atom:updated>2025-11-01T11:12:34.262Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*hoLmEGIyEWQ2P04a_sf_Rw.png" /></figure><p>When I began preparing for Android interviews in January 2025, I had no idea it would take nearly 9–10 months to land my next job offer. Despite having two years of Android development experience, I struggled to answer even the most basic questions in my first several interviews. It was a humbling experience, but I kept showing up, learning from each attempt, and hoping for the best.</p><p>If you’re in a similar phase, I know exactly how it feels — the uncertainty, the frustration, and the constant self-doubt. What truly helped me was documenting every interview question I encountered and preparing for it thoroughly afterward. Over time, this practice not only improved my confidence but also deepened my understanding of Android fundamentals.</p><p>In this article, The questions you are going to see are the most recent questions asked by various mid to top level companies for the android role and I’ve compiled and categorized those interview questions into three levels, hoping they’ll guide others on the same journey toward growth and success.</p><blockquote><strong>Easy </strong>🟢 -&gt; Definitions, simple concepts, basic differences, lifecycle, OOPs, syntax.</blockquote><blockquote><strong>Medium </strong>🟠 -&gt; Architecture, lifecycle edge cases, coroutines, threading, local storage, encryption, caching.</blockquote><blockquote><strong>Hard </strong>🔴 -&gt; Advanced architecture, Compose internals, encryption, CI/CD, debugging, multi-module, DSA.</blockquote><p>Lets directly jump into the questions :-</p><p>Easy Level 🟢 :-</p><h3>1️⃣ What are the main components of Android?</h3><p>Android applications are built using four main components — Activities, Services, Broadcast Receivers, and Content Providers. Each component serves a specific purpose in the app’s architecture. Activities handle the UI, Services perform background tasks, Broadcast Receivers listen to system events, and Content Providers manage and share app data securely between applications.</p><h3>2️⃣ What is an Intent in Android?</h3><p>In Android, an Intent is a messaging object used for communication between different components such as Activities, Services, and Broadcast Receivers. It allows us to specify an action to be performed, and it can also carry data between components using a Bundle (via methods like putExtra()). There are two main types of Intents:<br><strong>Implicit Intent </strong>— Used when a specific target component is not mentioned. Instead, only the action is specified, and the Android system decides which app or component can best handle it. Example: Requesting to enable Bluetooth or open a web page.<br><strong>Explicit Intent</strong> — Used when a specific target component within the same app is mentioned directly (like an Activity or Service). It’s commonly used inside the app to navigate between screens or start background services. Example: Launching a MainActivity from a LoginActivity or starting a MusicService.</p><h3>3️⃣ What is an Activity in Android?</h3><p>An Activity in Android represents a single screen with a user interface. It acts as the main entry point for user interaction with the app and is a subclass of the Activity or AppCompatActivity class. The Android system manages its lifecycle through callback methods such as onCreate, onStart, onResume, onPause, onStop, and onDestroy. Each Activity must be declared in the AndroidManifest.xml file.</p><h3>4️⃣ What is the Activity Lifecycle?</h3><p>The Activity Lifecycle defines how an Activity behaves as it transitions between different states. Key states include Created, Started, Resumed, Paused, Stopped, and Destroyed. The system invokes corresponding callback methods like <strong>onCreate()</strong>, <strong>onStart()</strong>, and <strong>onResume()</strong> when launching, and <strong>onPause()</strong>, <strong>onStop()</strong>, and <strong>onDestroy()</strong> when closing. Understanding this lifecycle helps in managing resources efficiently and preventing memory leaks.</p><h3>5️⃣ What is a Service in Android?</h3><p>A Service is a component used to perform long-running operations in the background without a user interface. It allows tasks to continue even when the user switches to another app. Examples include playing music or fetching data from the network. Services can be started or bound, and they must be declared in the AndroidManifest.xml file.</p><h3>6️⃣ What is the difference between a Started Service and a Bound Service?</h3><p>A Started Service is initiated using startService() and runs independently in the background until it stops itself or is stopped by another component. A Bound Service is started using bindService(), where components bind to it to interact and exchange data. When all bound components are unbound, the service automatically stops.</p><h3>7️⃣ What is a Broadcast Receiver?</h3><p>A Broadcast Receiver is a component that listens for system-wide or application-specific broadcast messages. It allows the app to respond to events such as network changes, incoming messages, or device reboots. Broadcast Receivers run in the background and are typically registered either in the AndroidManifest.xml or dynamically in code using registerReceiver().</p><h3>8️⃣ What is a Content Provider?</h3><p>A Content Provider manages access to a structured set of app data and allows data sharing between different applications. It provides a standard interface to query, insert, update, and delete data using URIs. Common examples include Contacts and MediaStore. Content Providers are especially useful when one app needs to share data securely with another app.</p><h3>9️⃣ What is the AndroidManifest.xml file?</h3><p>The AndroidManifest.xml file is the central configuration file of every Android app. It defines essential information such as app permissions, declared components (Activities, Services, Broadcast Receivers, and Content Providers), intent filters, and app metadata. The system uses this file to understand the structure and behavior of the application before it runs.</p><h3>🔟 What is a Fragment in Android?</h3><p>A Fragment is a modular section of an Activity that represents a part of the user interface. It has its own lifecycle and can be reused across multiple activities. Fragments help create dynamic and flexible UI designs, especially on tablets. They must be hosted within an Activity and can be added or replaced dynamically using FragmentTransactions.</p><p>These were the first 10 easy-level Android interview questions. You can explore these topics in more depth to strengthen your understanding and confidently handle any follow-up questions during interviews. In the upcoming article, we’ll cover those follow-up questions and take a deeper dive into each concept — so stay tuned!</p><p>Thank you for reading till the end. See you in the next article!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=5de8cd8a4507" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Simple See and Share meme App using Retrofit in Android studio.]]></title>
            <link>https://medium.com/@maheshvhatkar82/simple-see-and-share-meme-app-using-retrofit-in-android-studio-4d86c0cd321d?source=rss-4ea6661e33b4------2</link>
            <guid isPermaLink="false">https://medium.com/p/4d86c0cd321d</guid>
            <category><![CDATA[mvvm-databinding]]></category>
            <category><![CDATA[glide]]></category>
            <category><![CDATA[retrofit]]></category>
            <category><![CDATA[android-app-development]]></category>
            <category><![CDATA[mvvm-architecture]]></category>
            <dc:creator><![CDATA[Mahesh Vhatkar]]></dc:creator>
            <pubDate>Sat, 30 Mar 2024 12:09:50 GMT</pubDate>
            <atom:updated>2024-04-03T05:20:44.245Z</atom:updated>
            <content:encoded><![CDATA[<p>All of us use multiple social media apps to consume content like Memes, News, Entertainment, Infotainment etc. You can make your own simple Meme app using Retrofit API library in Android studio. Lets get started 🌟</p><p>At the end you will be able to create this output as shown below.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/576/1*Afx28T0MWfzAX-03fqggaQ.gif" /></figure><p>This is first version of Meme app, so we keep it <strong>basic</strong> and <strong>simple</strong>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/498/1*V_DfGlDYkjpO6MNLdVZBpg.gif" /></figure><p><strong>Requirements</strong>:-</p><ol><li>Android Studio</li><li>Basic knowledge of MVVM architecture. (optional)</li><li>Basic knowledge of Data binding. (optional)</li></ol><p><strong>Step 0 -&gt; Setup </strong>:-</p><p>Assuming you have installed Android studio in your PC. Launch Android studio and create a new project. Choose an empty template.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*OmMxj11XFTuWjw-zjzhRCw.png" /></figure><p>Give name to the project as “<strong>See Share Meme App</strong>”. Click on finish.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*_xqT4PoGjlccigL8_ewVIA.png" /></figure><p>Let the project build. And now you if you run this project you will see a screen with “<strong>Hello World</strong>” text.</p><p><strong>Step 1. -&gt; Create UI page</strong></p><p>Lets create the main UI page. Main page has these UI elements.</p><ol><li>Header (“See Share Meme”)</li><li>ImageView (to show Meme as an image)</li><li>Next Button ( to load next meme )</li><li>Share Button (to share the meme)</li></ol><p>We are going to use<strong> D</strong><a href="https://medium.com/@maheshvhatkar82/using-mvvm-and-databinding-in-android-studio-project-da2d14d00595"><strong>atabinding</strong></a><strong> </strong>and<strong> </strong><a href="https://medium.com/@maheshvhatkar82/using-mvvm-and-databinding-in-android-studio-project-da2d14d00595"><strong>MVVM</strong></a> Architecture in this App. You can redirect to<strong><em> </em></strong><a href="https://medium.com/@maheshvhatkar82/using-mvvm-and-databinding-in-android-studio-project-da2d14d00595"><strong>this</strong></a> article if you want to know more about these topics.</p><p>Enable data binding feature in your project as given below.</p><p>Navigate to “<strong>Build.gradle</strong>” file in your project and add this</p><pre>buildFeatures<br>{<br>    dataBinding = true<br>}</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/875/0*rQPbTzpKjQNqvQFf.jpg" /></figure><p>Add Internet permission in <strong>app -&gt; src -&gt; main -&gt; AndroidManifest.xml</strong><em>. Paste the below code into it.</em></p><pre>&lt;uses-permission android:name=&quot;android.permission.INTERNET&quot;/&gt;</pre><p>Now go to your “<strong>activity_main.xml</strong>” ( res -&gt; layout -&gt; activity_main.xml). And paste below xml code in it.</p><pre>&lt;?xml version=&quot;1.0&quot; encoding=&quot;utf-8&quot;?&gt;<br>&lt;layout xmlns:android=&quot;http://schemas.android.com/apk/res/android&quot;<br>    xmlns:app=&quot;http://schemas.android.com/apk/res-auto&quot;<br>    xmlns:tools=&quot;http://schemas.android.com/tools&quot;&gt;<br><br>        &lt;androidx.constraintlayout.widget.ConstraintLayout<br>            android:layout_width=&quot;match_parent&quot;<br>            android:layout_height=&quot;match_parent&quot;<br>            tools:context=&quot;.MainActivity&quot;&gt;<br><br>        &lt;/androidx.constraintlayout.widget.ConstraintLayout&gt;<br><br>&lt;/layout&gt;</pre><p>We use <strong>ConstraintLayout</strong> with databinding and enclosed it within a simple <strong>layout</strong> as shown above. Lets add UI elements one by one into our xml.</p><ul><li>Add the heading as “<strong>See Share Meme</strong>”. The code looks like -&gt;</li></ul><pre>&lt;?xml version=&quot;1.0&quot; encoding=&quot;utf-8&quot;?&gt;<br>&lt;layout xmlns:android=&quot;http://schemas.android.com/apk/res/android&quot;<br>    xmlns:app=&quot;http://schemas.android.com/apk/res-auto&quot;<br>    xmlns:tools=&quot;http://schemas.android.com/tools&quot;&gt;<br><br>        &lt;androidx.constraintlayout.widget.ConstraintLayout<br>            android:layout_width=&quot;match_parent&quot;<br>            android:layout_height=&quot;match_parent&quot;<br>            tools:context=&quot;.MainActivity&quot;&gt;<br><br>            &lt;TextView<br>                android:id=&quot;@+id/app_name_textview&quot;<br>                android:layout_width=&quot;match_parent&quot;<br>                android:layout_height=&quot;60dp&quot;<br>                app:layout_constraintStart_toStartOf=&quot;parent&quot;<br>                app:layout_constraintTop_toTopOf=&quot;parent&quot;<br>                android:text=&quot;@string/app_name&quot;<br>                android:gravity=&quot;center&quot;<br>                android:textSize=&quot;20sp&quot;<br>                android:textColor=&quot;@color/black&quot;<br>                /&gt;<br><br>        &lt;/androidx.constraintlayout.widget.ConstraintLayout&gt;<br><br>&lt;/layout&gt;</pre><ul><li>Similarly add ImageView.</li></ul><pre>&lt;?xml version=&quot;1.0&quot; encoding=&quot;utf-8&quot;?&gt;<br>&lt;layout xmlns:android=&quot;http://schemas.android.com/apk/res/android&quot;<br>    xmlns:app=&quot;http://schemas.android.com/apk/res-auto&quot;<br>    xmlns:tools=&quot;http://schemas.android.com/tools&quot;&gt;<br>    <br><br>        &lt;androidx.constraintlayout.widget.ConstraintLayout<br>            android:layout_width=&quot;match_parent&quot;<br>            android:layout_height=&quot;match_parent&quot;<br>            tools:context=&quot;.MainActivity&quot;&gt;<br><br>            &lt;TextView<br>                android:id=&quot;@+id/app_name_textview&quot;<br>                android:layout_width=&quot;match_parent&quot;<br>                android:layout_height=&quot;60dp&quot;<br>                app:layout_constraintStart_toStartOf=&quot;parent&quot;<br>                app:layout_constraintTop_toTopOf=&quot;parent&quot;<br>                android:text=&quot;@string/app_name&quot;<br>                android:gravity=&quot;center&quot;<br>                android:textSize=&quot;20sp&quot;<br>                android:textColor=&quot;@color/black&quot;<br>                /&gt;<br>            &lt;ImageView<br>                android:id=&quot;@+id/meme_imageview&quot;<br>                android:layout_width=&quot;match_parent&quot;<br>                android:layout_height=&quot;400dp&quot;<br>                app:layout_constraintStart_toStartOf=&quot;parent&quot;<br>                app:layout_constraintBottom_toBottomOf=&quot;parent&quot;<br>                android:layout_marginBottom=&quot;40dp&quot;<br>                app:layout_constraintTop_toBottomOf=&quot;@+id/app_name_textview&quot;<br>                android:contentDescription=&quot;Meme&quot;<br>                &gt;<br>            &lt;/ImageView&gt;<br>            <br><br>        &lt;/androidx.constraintlayout.widget.ConstraintLayout&gt;<br><br>&lt;/layout&gt;</pre><ul><li>Now add two buttons to your layout.</li></ul><pre>&lt;?xml version=&quot;1.0&quot; encoding=&quot;utf-8&quot;?&gt;<br>&lt;layout xmlns:android=&quot;http://schemas.android.com/apk/res/android&quot;<br>    xmlns:app=&quot;http://schemas.android.com/apk/res-auto&quot;<br>    xmlns:tools=&quot;http://schemas.android.com/tools&quot;&gt;<br>    <br><br>        &lt;androidx.constraintlayout.widget.ConstraintLayout<br>            android:layout_width=&quot;match_parent&quot;<br>            android:layout_height=&quot;match_parent&quot;<br>            tools:context=&quot;.MainActivity&quot;&gt;<br><br>            &lt;TextView<br>                android:id=&quot;@+id/app_name_textview&quot;<br>                android:layout_width=&quot;match_parent&quot;<br>                android:layout_height=&quot;60dp&quot;<br>                app:layout_constraintStart_toStartOf=&quot;parent&quot;<br>                app:layout_constraintTop_toTopOf=&quot;parent&quot;<br>                android:text=&quot;@string/app_name&quot;<br>                android:gravity=&quot;center&quot;<br>                android:textSize=&quot;20sp&quot;<br>                android:textColor=&quot;@color/black&quot;<br>                /&gt;<br>            &lt;ImageView<br>                android:id=&quot;@+id/meme_imageview&quot;<br>                android:layout_width=&quot;match_parent&quot;<br>                android:layout_height=&quot;400dp&quot;<br>                app:layout_constraintStart_toStartOf=&quot;parent&quot;<br>                app:layout_constraintBottom_toBottomOf=&quot;parent&quot;<br>                android:layout_marginBottom=&quot;40dp&quot;<br>                app:layout_constraintTop_toBottomOf=&quot;@+id/app_name_textview&quot;<br>                android:contentDescription=&quot;Meme&quot;<br>                &gt;<br>            &lt;/ImageView&gt;<br>            &lt;Button<br>                android:id=&quot;@+id/share_button&quot;<br>                android:layout_width=&quot;150dp&quot;<br>                android:layout_height=&quot;90dp&quot;<br>                app:layout_constraintBottom_toBottomOf=&quot;parent&quot;<br>                app:layout_constraintStart_toStartOf=&quot;parent&quot;<br>                android:text=&quot;Share&quot;<br>                android:requiresFadingEdge=&quot;vertical&quot;<br>                app:layout_constraintEnd_toStartOf=&quot;@+id/next_button&quot;<br>                /&gt;<br>            &lt;Button<br>                android:id=&quot;@+id/next_button&quot;<br>                android:layout_width=&quot;150dp&quot;<br>                android:layout_height=&quot;90dp&quot;<br>                app:layout_constraintBottom_toBottomOf=&quot;parent&quot;<br>                app:layout_constraintEnd_toEndOf=&quot;parent&quot;<br>                android:text=&quot;Next&quot;<br>                android:requiresFadingEdge=&quot;vertical&quot;<br>                app:layout_constraintStart_toEndOf=&quot;@+id/share_button&quot;<br>                /&gt;<br><br>        &lt;/androidx.constraintlayout.widget.ConstraintLayout&gt;<br><br>&lt;/layout&gt;</pre><p>Your layout looks like this now. and you have completed your UI page.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/322/1*zu7naqyrTXRdVZ8WaSpuFg.png" /><figcaption>Main Page</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/498/1*VX2U9ozHFNfMHfvMCc7o_Q.gif" /></figure><p>Good Job 👋. Currently buttons would not respond. and ImageView doesn’t show any content. Its just a dumb UI. Lets add some functionalities to these buttons in the next step.</p><p><strong>Step 2 -&gt; Add functionalities to the UI.</strong></p><p>Lets add a listener functions to the buttons to perform a particular task when button is pressed. Create a new package by right clicking on package name <strong>com.example.seesharememeapp </strong>( the package name may vary ) -&gt; <strong>New</strong> -&gt; <strong>Package</strong>. Name it as “<strong>listener</strong>”.</p><p>Create an interface inside listener package by right clicking on <strong>listener -&gt; New -&gt; Kotlin Class/File.</strong> Choose interface and name it as <strong>“mainListener” </strong>Add code below to it.</p><pre>package com.example.seesharememeapplication.listener<br><br>interface MainListener {<br><br>    fun onShare(){}<br>    fun onNext(){}<br>    fun onSuccess(previewImg: String?) {}<br>}</pre><ul><li><strong>onShare()</strong> -&gt; triggers when user clicks on Share button.</li><li><strong>onNext()</strong> -&gt; triggers when user clicks on Next button.</li><li><strong>onSuccess()</strong> -&gt; triggers when Success resposne come from Api.</li></ul><p>Lets create a ViewModel. Create a new package (right click on <strong>com.example.seeshareapp</strong> -&gt; <strong>New</strong> -&gt; <strong>Package</strong>) name it as “<strong>viewModel</strong>”.</p><p>Create a Kotlin/Class file inside it and name it as “<strong>MainViewModel.kt</strong>”. Paste the code below into it.</p><pre>package com.example.seesharememeapplication.viewModel<br><br>import android.view.View<br>import androidx.lifecycle.ViewModel<br>import com.example.seesharememeapplication.listener.MainListener<br><br>class MainViewModel : ViewModel() {<br><br>    var mainListener : MainListener? = null<br>    fun onShareClicked(view : View) {<br>        mainListener?.onShare()<br>    }<br><br>    fun onNextClicked(view: View) {<br>        mainListener?.onNext()<br>    }<br>}</pre><p>We have initialzed <strong>ManiViewModel</strong> Class as <strong>ViewModel. </strong>Created a variable “<strong>mainListener</strong>” inside the class. We created two functions “<strong>onShareClicked</strong>” and “<strong>onNextClicked</strong>” two handle the user click action. Inside these functions we used the “<strong>mainListener</strong>” variable and called <strong>onShare()</strong> and <strong>onNext() </strong>methods respectively.</p><p>Now we have created viewModel successfully also remember these two functions. we will use them in the xml file.</p><p>Lets get back to <strong>activity_main.xml. </strong>Add <strong>MainViewModel</strong> reference to the xml file as below. Paste below code to the .xml file.</p><pre>&lt;data&gt;<br>    &lt;variable<br>        name=&quot;viewmodelMain&quot;<br>        type=&quot;com.example.seesharememeapplication.viewModel.MainViewModel&quot; /&gt;<br>&lt;/data&gt;</pre><p>And to perform action when user clicks button. Add “<strong>onShareClicked</strong>” and “<strong>onNextClicked</strong>” functions to the onclickListener of the button tags.</p><pre>&lt;Button<br>    android:id=&quot;@+id/share_button&quot;<br>    android:layout_width=&quot;150dp&quot;<br>    android:layout_height=&quot;90dp&quot;<br>    app:layout_constraintBottom_toBottomOf=&quot;parent&quot;<br>    app:layout_constraintStart_toStartOf=&quot;parent&quot;<br>    android:text=&quot;Share&quot;<br>    android:requiresFadingEdge=&quot;vertical&quot;<br>    android:onClickListener=&quot;@{viewmodelMain::onShareClicked}&quot;// onclick listener for share button<br>    app:layout_constraintEnd_toStartOf=&quot;@+id/next_button&quot;<br>    /&gt;<br>&lt;Button<br>    android:id=&quot;@+id/next_button&quot;<br>    android:layout_width=&quot;150dp&quot;<br>    android:layout_height=&quot;90dp&quot;<br>    app:layout_constraintBottom_toBottomOf=&quot;parent&quot;<br>    app:layout_constraintEnd_toEndOf=&quot;parent&quot;<br>    android:text=&quot;Next&quot;<br>    android:requiresFadingEdge=&quot;vertical&quot;<br>    android:onClickListener=&quot;@{viewmodelMain::onNextClicked}&quot;// onclick listener for next button. <br>    app:layout_constraintStart_toEndOf=&quot;@+id/share_button&quot;<br>    /&gt;</pre><p>Now the .xml file finally looks like.</p><pre>&lt;?xml version=&quot;1.0&quot; encoding=&quot;utf-8&quot;?&gt;<br>&lt;layout xmlns:android=&quot;http://schemas.android.com/apk/res/android&quot;<br>    xmlns:app=&quot;http://schemas.android.com/apk/res-auto&quot;<br>    xmlns:tools=&quot;http://schemas.android.com/tools&quot;&gt;<br>    &lt;data&gt;<br>        &lt;variable<br>            name=&quot;viewmodelMain&quot;<br>            type=&quot;com.example.seesharememeapplication.viewModel.MainViewModel&quot; /&gt;<br>    &lt;/data&gt;<br><br>        &lt;androidx.constraintlayout.widget.ConstraintLayout<br>            android:layout_width=&quot;match_parent&quot;<br>            android:layout_height=&quot;match_parent&quot;<br>            tools:context=&quot;.MainActivity&quot;&gt;<br><br>            &lt;TextView<br>                android:id=&quot;@+id/app_name_textview&quot;<br>                android:layout_width=&quot;match_parent&quot;<br>                android:layout_height=&quot;60dp&quot;<br>                app:layout_constraintStart_toStartOf=&quot;parent&quot;<br>                app:layout_constraintTop_toTopOf=&quot;parent&quot;<br>                android:text=&quot;@string/app_name&quot;<br>                android:gravity=&quot;center&quot;<br>                android:textSize=&quot;20sp&quot;<br>                android:textColor=&quot;@color/black&quot;<br>                /&gt;<br>            &lt;ImageView<br>                android:id=&quot;@+id/meme_imageview&quot;<br>                android:layout_width=&quot;match_parent&quot;<br>                android:layout_height=&quot;400dp&quot;<br>                app:layout_constraintStart_toStartOf=&quot;parent&quot;<br>                app:layout_constraintBottom_toBottomOf=&quot;parent&quot;<br>                android:layout_marginBottom=&quot;40dp&quot;<br>                app:layout_constraintTop_toBottomOf=&quot;@+id/app_name_textview&quot;<br>                android:contentDescription=&quot;Meme&quot;<br>                &gt;<br>            &lt;/ImageView&gt;<br>            &lt;Button<br>                android:id=&quot;@+id/share_button&quot;<br>                android:layout_width=&quot;150dp&quot;<br>                android:layout_height=&quot;90dp&quot;<br>                app:layout_constraintBottom_toBottomOf=&quot;parent&quot;<br>                app:layout_constraintStart_toStartOf=&quot;parent&quot;<br>                android:text=&quot;Share&quot;<br>                android:requiresFadingEdge=&quot;vertical&quot;<br>                android:onClickListener=&quot;@{viewmodelMain::onShareClicked}&quot;<br>                app:layout_constraintEnd_toStartOf=&quot;@+id/next_button&quot;<br>                /&gt;<br>            &lt;Button<br>                android:id=&quot;@+id/next_button&quot;<br>                android:layout_width=&quot;150dp&quot;<br>                android:layout_height=&quot;90dp&quot;<br>                app:layout_constraintBottom_toBottomOf=&quot;parent&quot;<br>                app:layout_constraintEnd_toEndOf=&quot;parent&quot;<br>                android:text=&quot;Next&quot;<br>                android:requiresFadingEdge=&quot;vertical&quot;<br>                android:onClickListener=&quot;@{viewmodelMain::onNextClicked}&quot;<br>                app:layout_constraintStart_toEndOf=&quot;@+id/share_button&quot;<br>                /&gt;<br><br>        &lt;/androidx.constraintlayout.widget.ConstraintLayout&gt;<br><br>&lt;/layout&gt;</pre><p>Now redirect to <strong>MainActivity.kt</strong> file. Activity should be link with the viewModel created using databinding. Paste below code to the <strong>MainActivity</strong>.kt file.</p><pre>class MainActivity : AppCompatActivity(), MainListener {<br>    private lateinit var binding: ActivityMainBinding<br><br>    override fun onCreate(savedInstanceState: Bundle?) {<br>        super.onCreate(savedInstanceState)<br>        //setContentView(R.layout.activity_main)<br><br>        binding = DataBindingUtil.setContentView(this,R.layout.activity_main)<br>        val viewModel  = ViewModelProvider(this)[MainViewModel::class.java]<br>        binding.viewmodelMain = viewModel<br>        viewModel.mainListener = this<br><br>    }<br><br>    override fun onNext() {<br>        <br>    }<br><br>    override fun onShare() {<br><br>    }<br>}</pre><p>Here we have added MainListener interface to the MainActivity, so that we can override its methods. <strong>onNext</strong>(), <strong>onShare</strong>() and <strong>onSuccess</strong>() (We will use onSuccess later ). As of now we have <strong>onNext</strong> and <strong>onShare</strong> methods. Now to see if the buttons are interactive and performs given action after click event. Lets add a <strong>Toast</strong> when the buttons is clicked.</p><pre>class MainActivity : AppCompatActivity(), MainListener {<br>    private lateinit var binding: ActivityMainBinding<br><br>    override fun onCreate(savedInstanceState: Bundle?) {<br>        super.onCreate(savedInstanceState)<br>        //setContentView(R.layout.activity_main)<br><br>        binding = DataBindingUtil.setContentView(this,R.layout.activity_main)<br>        val viewModel  = ViewModelProvider(this)[MainViewModel::class.java]<br>        binding.viewmodelMain = viewModel<br>        viewModel.mainListener = this<br><br>    }<br>    override fun onSuccess() {<br>        //We will use this method later.<br>    }<br><br>    override fun onNext() {<br>        Toast.makeText(applicationContext, &quot;Next button clicked.&quot;, Toast.LENGTH_SHORT).show()<br><br>    }<br><br>    override fun onShare() {<br><br>        Toast.makeText(applicationContext, &quot;Share button clicked.&quot;, Toast.LENGTH_SHORT).show()<br>    }<br>}</pre><p>Try running the app and click on any button. you should see the toast showing the predefined the messages.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/576/1*qoibVy0iexetFyv7Hd_BGg.gif" /></figure><p>You have done a good job till here .</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/498/1*nAMROVeGyt9cgg2MXmv8UA.gif" /></figure><p><strong>Step 3 -&gt; Get the Meme from Api</strong></p><p>Have you used Retrofit library before for calling any Api. If not don’t worry. we cover that too.</p><p>You first need to add some dependencies in your project build.gradle file.</p><pre>//for Retrofit<br>implementation &#39;com.squareup.retrofit2:retrofit:2.9.0&#39;<br>implementation &#39;com.squareup.retrofit2:converter-gson:2.9.0&#39;<br>implementation &#39;com.squareup.okhttp3:okhttp:4.9.0&#39;<br>implementation &#39;com.squareup.okhttp3:logging-interceptor:4.9.0&#39;<br>implementation &#39;com.squareup.retrofit2:converter-scalars:2.9.0&#39;<br>implementation &#39;com.squareup.retrofit2:adapter-rxjava2:2.9.0&#39;<br><br>//glide to show an image to imageview.<br>implementation &#39;com.github.bumptech.glide:glide:4.12.0&#39;<br>annotationProcessor &#39;com.github.bumptech.glide:compiler:4.12.0&#39;</pre><p>After adding just sync your project with gradle files.</p><p>Now you are all set to use them.</p><p>We need three files to do an Api call.</p><ul><li><strong>GetMemeInterface</strong> -&gt; to add endpoint of Api and attach body to Api if necessary</li><li><strong>GetRetrofit</strong> -&gt; To get the retrofit object.</li><li><strong>GetMemeApiCall</strong> -&gt; To make Actual api call and handle the Api response.</li></ul><p>This may sound confusing at the first. You will understand while actually implementing it.</p><p>Lets create a package as we created before. and name it as “<strong>ApiCall</strong>”. Create a new kotlin file named as “<strong>ApiCallRetrofit</strong>”. paste below code into it.</p><pre>import okhttp3.OkHttpClient<br>import okhttp3.logging.HttpLoggingInterceptor<br>import retrofit2.Retrofit<br>import retrofit2.converter.gson.GsonConverterFactory<br>import retrofit2.converter.scalars.ScalarsConverterFactory<br><br>class GetRetrofit {<br>    var BASE_URL_UPLOAD = &quot;https://meme-api.com&quot;<br><br>    fun getRetrofit(): Retrofit? {<br>        val loggingInterceptor = HttpLoggingInterceptor()<br>        loggingInterceptor.setLevel(HttpLoggingInterceptor.Level.BODY)<br><br>        val client: OkHttpClient = OkHttpClient.Builder()<br>            .addInterceptor(loggingInterceptor)<br>            .build()<br><br>        return Retrofit.Builder()<br>            .client(client)<br>            .baseUrl(BASE_URL_UPLOAD)<br>            .addConverterFactory(ScalarsConverterFactory.create())<br>            .addConverterFactory(GsonConverterFactory.create())<br>            .build()<br>    }<br>}</pre><p>In this <strong>GetRetrofit</strong> class we return a Retrofit object. we created a variable for base url named as “<strong>BASE_URL_UPLOAD</strong>” = “https://meme-api.com&quot;.</p><p>Create another new <strong>kotlin Interface</strong> named as “<strong>GetMemeInterface.kt</strong>” inside the “ApiCall” package. Paste the below code into it.</p><pre>import okhttp3.ResponseBody<br>import retrofit2.Call<br>import retrofit2.http.GET<br><br><br>interface GetMemeInterface {<br><br>    @GET(&quot;/gimme&quot;)<br>    fun getMeme(): Call&lt;ResponseBody?&gt;?<br>}</pre><p>Here we added the endpoint of the Url and calling the Api with GET method annoted. The getmeme() method will be used in the <strong>GetMemeApiCall</strong>.kt file</p><p>Lets create “<strong>GetMemeApiCall.kt</strong>” new file. Paste the below code into it.</p><pre>import android.content.Context<br>import android.widget.Toast<br>import com.example.seesharememeapplication.listener.MainListener<br>import okhttp3.ResponseBody<br>import org.json.JSONObject<br>import retrofit2.Call<br>import retrofit2.Callback<br>import retrofit2.Response<br><br><br>class GetMemeApiCall {<br><br>    fun getMeme(context: Context, apiCallback : MainListener) {<br>        val getResponse: GetMemeInterface? = GetRetrofit().getRetrofit()?.create(GetMemeInterface::class.java)<br>        val call: Call&lt;ResponseBody?&gt;? = getResponse?.getMeme()<br><br>        call?.enqueue(object : Callback&lt;ResponseBody?&gt; {<br>            override fun onResponse(call: Call&lt;ResponseBody?&gt;, response: Response&lt;ResponseBody?&gt;) {<br>                if (response.body()!= null) {<br>                    val responseJson: JSONObject? = JSONObject(response.body()!!.string())<br>                    val previewImg: String? = responseJson?.getString(&quot;url&quot;)<br>                    apiCallback.onSuccess(previewImg)<br>                } else {<br>                    Toast.makeText(context,response.errorBody()?.string(),Toast.LENGTH_LONG).show()<br>                }<br>            }<br><br>            override fun onFailure(call: Call&lt;ResponseBody?&gt;, t: Throwable) {<br>                Toast.makeText(context, t.toString(),Toast.LENGTH_LONG).show()<br>            }<br><br>        })<br>    }<br>}</pre><p>Here you are handling the main Api call event by using “<strong>GetMemeInterface.kt</strong>” and “<strong>GetRetrofit.kt</strong>” file methods. Inside the <strong>onResponse() </strong>we get the response from the Api and we converting it to JsonObject. finally we call the <strong>onSuccess()</strong> method of <strong>MainListener.kt</strong> here.</p><p>You can see we pass the Api response to the onSuccess() method as “<strong>previewImg</strong>”. If we receives any invalid response from the Api we Toast the Error to screen.</p><p>Here we have our Retrofit Api call ready to call. Lets call this <strong>getMeme()</strong> function in the <strong>MainActivity.kt.</strong></p><p><strong>Step 4 -&gt; Use glide library to show the meme on screen.</strong></p><p>You have already added glide library dependency in the build.gradle file. Now we want to get a meme each time user clicks on Next button. So we need to add the Api call inside the method “<strong>onNext()</strong>”. the onNext method should look like.</p><pre>override fun onNext() {<br>    Toast.makeText(applicationContext, &quot;Next button clicked.&quot;, Toast.LENGTH_SHORT).show()<br>    GetMemeApiCall().getMeme(applicationContext,object: MainListener{<br>        override fun onSuccess(previewImg: String?) {<br>            Glide.with(applicationContext)<br>                .load(previewImg)<br>                .into(binding.memeImageview)<br><br>            Glide.with(applicationContext)<br>                .asBitmap()<br>                .load(previewImg)<br>                .into(object : SimpleTarget&lt;Bitmap&gt;() {<br>                    override fun onResourceReady(resource: Bitmap, transition: Transition&lt;in Bitmap&gt;?) {<br>                        // Now &#39;resource&#39; contains the Bitmap representation of the image<br>                        // You can use this Bitmap with BitmapFactory or any other image processing library<br>                        imageViewBitmap = resource<br>                        // Your further processing with the Bitmap<br>                        // For example, passing it to BitmapFactory<br>                        // BitmapFactory.decodeResource(resources, R.drawable.your_drawable)<br><br>                        // Now you can share or perform other operations with the Bitmap<br>                    }<br>                })<br>        }<br>    })<br><br>}</pre><p>Here you can see that we called the<strong> getMeme()</strong> function. and we have used <strong>onSuccess()</strong> method in the <strong>MainListener.kt</strong> to fetch the image info in string format. After this, We use glide library code to convert the string format Image info to bitmap format. and we load the image into the ImageView of the UI page. We are all done with onNext() function.</p><p>Also as you can see we have utilized the onSuccess() method inside the onNext() method. so you can remove it from the MainActivity.kt file. Now the MainActivity.kit should look like this.</p><pre>import android.graphics.Bitmap<br>import android.os.Bundle<br>import android.widget.Toast<br>import androidx.appcompat.app.AppCompatActivity<br>import androidx.databinding.DataBindingUtil<br>import androidx.lifecycle.ViewModelProvider<br>import com.bumptech.glide.Glide<br>import com.bumptech.glide.request.target.SimpleTarget<br>import com.bumptech.glide.request.transition.Transition<br>import com.example.seesharememeapplication.ApiCall.GetMemeApiCall<br>import com.example.seesharememeapplication.databinding.ActivityMainBinding<br>import com.example.seesharememeapplication.listener.MainListener<br>import com.example.seesharememeapplication.viewModel.MainViewModel<br><br>class MainActivity : AppCompatActivity(), MainListener {<br>    private lateinit var binding: ActivityMainBinding<br>    var imageViewBitmap : Bitmap? = null<br><br>    override fun onCreate(savedInstanceState: Bundle?) {<br>        super.onCreate(savedInstanceState)<br>        //setContentView(R.layout.activity_main)<br><br>        binding = DataBindingUtil.setContentView(this,R.layout.activity_main)<br>        val viewModel  = ViewModelProvider(this)[MainViewModel::class.java]<br>        binding.viewmodelMain = viewModel<br>        viewModel.mainListener = this<br><br>    }<br><br>    override fun onNext() {<br>        Toast.makeText(applicationContext, &quot;Next button clicked.&quot;, Toast.LENGTH_SHORT).show()<br>        GetMemeApiCall().getMeme(applicationContext,object: MainListener{<br>            override fun onSuccess(previewImg: String?) {<br>                Glide.with(applicationContext)<br>                    .load(previewImg)<br>                    .into(binding.memeImageview)<br><br>                Glide.with(applicationContext)<br>                    .asBitmap()<br>                    .load(previewImg)<br>                    .into(object : SimpleTarget&lt;Bitmap&gt;() {<br>                        override fun onResourceReady(resource: Bitmap, transition: Transition&lt;in Bitmap&gt;?) {<br>                            // Now &#39;resource&#39; contains the Bitmap representation of the image<br>                            // You can use this Bitmap with BitmapFactory or any other image processing library<br>                            imageViewBitmap = resource<br>                            // Your further processing with the Bitmap<br>                            // For example, passing it to BitmapFactory<br>                            // BitmapFactory.decodeResource(resources, R.drawable.your_drawable)<br><br>                            // Now you can share or perform other operations with the Bitmap<br>                        }<br>                    })<br>            }<br>        })<br><br>    }<br><br>    override fun onShare() {<br>        Toast.makeText(applicationContext, &quot;Share button clicked.&quot;, Toast.LENGTH_SHORT).show()<br>        <br><br>    }<br>}</pre><p><strong>Step 5-&gt; Make Share button usable to share Meme.</strong></p><p>This is the last step in this article. We need to configure the share button to share the meme. You can share meme to your friends on whatsapp, insta or any social media app.</p><p>Just add the below code to the <strong>onShare() </strong>method.</p><pre>override fun onShare() {<br>    Toast.makeText(applicationContext, &quot;Share button clicked.&quot;, Toast.LENGTH_SHORT).show()<br>    val intent = Intent()<br>    intent.action = Intent.ACTION_SEND<br>    val path = MediaStore.Images.Media.insertImage(contentResolver,imageViewBitmap,&quot;Image&quot;, null)<br>    val uri = Uri.parse(path)<br>    intent.putExtra(Intent.EXTRA_STREAM,uri)<br>    intent.type = &quot;image/*&quot;<br>    startActivity(Intent.createChooser(intent,&quot;Share To : &quot;))<br><br>}<br></pre><p>The final MainActivity.kt is ready .</p><pre>import android.content.Intent<br>import android.graphics.Bitmap<br>import android.net.Uri<br>import android.os.Bundle<br>import android.provider.MediaStore<br>import android.widget.Toast<br>import androidx.appcompat.app.AppCompatActivity<br>import androidx.databinding.DataBindingUtil<br>import androidx.lifecycle.ViewModelProvider<br>import com.bumptech.glide.Glide<br>import com.bumptech.glide.request.target.SimpleTarget<br>import com.bumptech.glide.request.transition.Transition<br>import com.example.seesharememeapplication.ApiCall.GetMemeApiCall<br>import com.example.seesharememeapplication.databinding.ActivityMainBinding<br>import com.example.seesharememeapplication.listener.MainListener<br>import com.example.seesharememeapplication.viewModel.MainViewModel<br><br>class MainActivity : AppCompatActivity(), MainListener {<br>    private lateinit var binding: ActivityMainBinding<br>    var imageViewBitmap : Bitmap? = null<br><br>    override fun onCreate(savedInstanceState: Bundle?) {<br>        super.onCreate(savedInstanceState)<br>        //setContentView(R.layout.activity_main)<br><br>        binding = DataBindingUtil.setContentView(this,R.layout.activity_main)<br>        val viewModel  = ViewModelProvider(this)[MainViewModel::class.java]<br>        binding.viewmodelMain = viewModel<br>        viewModel.mainListener = this<br><br>    }<br><br>    override fun onNext() {<br>        Toast.makeText(applicationContext, &quot;Next button clicked.&quot;, Toast.LENGTH_SHORT).show()<br>        GetMemeApiCall().getMeme(applicationContext,object: MainListener{<br>            override fun onSuccess(previewImg: String?) {<br>                Glide.with(applicationContext)<br>                    .load(previewImg)<br>                    .into(binding.memeImageview)<br><br>                Glide.with(applicationContext)<br>                    .asBitmap()<br>                    .load(previewImg)<br>                    .into(object : SimpleTarget&lt;Bitmap&gt;() {<br>                        override fun onResourceReady(resource: Bitmap, transition: Transition&lt;in Bitmap&gt;?) {<br>                            // Now &#39;resource&#39; contains the Bitmap representation of the image<br>                            // You can use this Bitmap with BitmapFactory or any other image processing library<br>                            imageViewBitmap = resource<br>                            // Your further processing with the Bitmap<br>                            // For example, passing it to BitmapFactory<br>                            // BitmapFactory.decodeResource(resources, R.drawable.your_drawable)<br><br>                            // Now you can share or perform other operations with the Bitmap<br>                        }<br>                    })<br>            }<br>        })<br><br>    }<br><br>    override fun onShare() {<br>        Toast.makeText(applicationContext, &quot;Share button clicked.&quot;, Toast.LENGTH_SHORT).show()<br>        val intent = Intent()<br>        intent.action = Intent.ACTION_SEND<br>        val path = MediaStore.Images.Media.insertImage(contentResolver,imageViewBitmap,&quot;Image&quot;, null)<br>        val uri = Uri.parse(path)<br>        intent.putExtra(Intent.EXTRA_STREAM,uri)<br>        intent.type = &quot;image/*&quot;<br>        startActivity(Intent.createChooser(intent,&quot;Share To : &quot;))<br><br>    }<br>}</pre><p>This launches an intent to share the Meme image. Yesss…finally the implementation part is over. You did it. Well done….🌟 .</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/498/1*gvGczxmHMgI2NMXySyN57A.gif" /></figure><p>Now its time to run and test your First See and Share Meme Application.</p><p>Run the app and click on Next button. You should see the Meme appeared on the ImageView.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/576/1*Afx28T0MWfzAX-03fqggaQ.gif" /></figure><p>Thank you so much if you followed till now. You did a great job.</p><p>Let me know in the comments if you enjoyed the article. also if you have any query.</p><p>See you soon. Have a good day.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/498/1*-zC2Km9XtLdMv02RJTIJGA.gif" /></figure><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=4d86c0cd321d" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Using MVVM and Databinding in Android Studio project.]]></title>
            <link>https://medium.com/@maheshvhatkar82/using-mvvm-and-databinding-in-android-studio-project-da2d14d00595?source=rss-4ea6661e33b4------2</link>
            <guid isPermaLink="false">https://medium.com/p/da2d14d00595</guid>
            <category><![CDATA[android-studio]]></category>
            <category><![CDATA[viewmodel]]></category>
            <category><![CDATA[mvvm-databinding]]></category>
            <dc:creator><![CDATA[Mahesh Vhatkar]]></dc:creator>
            <pubDate>Thu, 19 Oct 2023 05:50:02 GMT</pubDate>
            <atom:updated>2023-10-19T05:50:02.993Z</atom:updated>
            <content:encoded><![CDATA[<p>I have recently worked on a project where I created a UI page to take inputs from user and later use these inputs in the main activity. In this project I used <a href="https://medium.com/swlh/understanding-mvvm-architecture-in-android-aa66f7e1a70b"><strong>MVVM architecture</strong></a><strong> + </strong><a href="https://medium.com/enpassio/introduction-to-android-data-binding-3d332c39a72b"><strong>Databinding</strong></a> to achieve the result.</p><p><strong>MVVM Architecture :-</strong></p><p>MVVM (Model-View-ViewModel) is an Architecture which divides the code flow into different layers. It becomes easy to separate the codebase also makes it more flexible. MVVM is readable to beginner and easy to maintain.</p><p><strong>Data Binding :-</strong></p><p>It is a method to bind UI elements with our activity and access them easily instead of setting up all UI elements programmatically. We can directly bind the .xml file elements with our activity. so no need to declare it using “findViewById()” like we do in “View Binding”. You will understand as we go further.</p><p>Let’s move to project. Firstly we need to enable data binding in the Android studio project.</p><p><strong>Step 1: Enable Data Binding</strong></p><p>Navigate to “<strong>Build.gradle</strong>” file in your android studio project and add this</p><pre>buildFeatures<br>{<br>    dataBinding = true<br>}</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1000/0*0rE48ackxXNZJUrk.jpg" /></figure><p><strong>Step 2: Create a new Activity</strong></p><p>Create a new Activity by choosing the folder under which you want to create it. Right click on folder -&gt;<strong>New -&gt; Activity -&gt; Empty Activity.</strong> select check box “Generate layout file”. Now you have created an activity with layout file. We need to make the layout file databinding compatible. We use Coordinator layout in data binding. Go to xml file (<strong>activity_temp.xml</strong>) generated. and paste below code.</p><pre>&lt;?xml version=&quot;1.0&quot; encoding=&quot;utf-8&quot;?&gt;<br>&lt;layout xmlns:android=&quot;http://schemas.android.com/apk/res/android&quot;<br>    xmlns:app=&quot;http://schemas.android.com/apk/res-auto&quot;<br>    xmlns:tools=&quot;http://schemas.android.com/tools&quot;&gt;<br><br>    &lt;data&gt;<br>        &lt;variable<br>            name=&quot;viewmodelTemp&quot;<br>            type=&quot;com.example.android.viewModel.TempViewModel&quot; /&gt;<br>    &lt;/data&gt;<br><br>    &lt;androidx.coordinatorlayout.widget.CoordinatorLayout<br><br>/// Main code goes here.<br><br>    &lt;/androidx.coordinatorlayout.widget.CoordinatorLayout&gt;<br><br>&lt;/layout&gt;<br></pre><p>In the above code, we used <strong>&lt;data&gt;</strong> and <strong>&lt;variable&gt;</strong> tags to bind <strong>Viewmodel</strong> with your activity and xml file. Lets take quick look on <strong>ViewModel.</strong></p><p><strong>ViewModel</strong> : —</p><p>The purpose of the ViewModel is to acquire and keep the information that is necessary for an Activity or a Fragment. The Activity or the Fragment should be able to observe changes in the ViewModel. ViewModels usually expose this information via <a href="https://developer.android.com/reference/android/arch/lifecycle/LiveData">LiveData</a> or Android Data Binding.</p><blockquote>the name assigned to viewmodel is “<strong>viewmodelTemp</strong>”.</blockquote><blockquote>path of viewmodel is “<strong>com.example.android.bluetoothlegatt.viewModel.TempViewModel”</strong></blockquote><p>Now we need to create one Viewmodel.</p><p><strong>Step 3: Create Viewmodel</strong></p><p>Create a new package as “viewModel”. Also create a new kotlin file inside it (<strong>New -&gt; Kotlin class/File</strong>) named “<strong>TempViewModel</strong>”. and paste below code into it.</p><pre>package com.example.android.bluetoothlegatt.viewModel<br><br>import android.view.View<br>import androidx.lifecycle.ViewModel<br>import com.example.android.bluetoothlegatt.listener.InfosecConvListener<br><br>class TempViewModel : ViewModel() {<br><br>    //main code goes here.<br>}</pre><p>We have basic viewmodel class implemented. lets add some elements to our <strong>activity_temp.xml</strong> like button and Textview. The .xml will look like below.</p><pre>&lt;?xml version=&quot;1.0&quot; encoding=&quot;utf-8&quot;?&gt;<br>&lt;layout xmlns:android=&quot;http://schemas.android.com/apk/res/android&quot;<br>    xmlns:app=&quot;http://schemas.android.com/apk/res-auto&quot;<br>    xmlns:tools=&quot;http://schemas.android.com/tools&quot;&gt;<br><br>    &lt;data&gt;<br>        &lt;variable<br>            name=&quot;viewmodelTemp&quot;<br>            type=&quot;com.example.android.viewModel.TempViewModel&quot; /&gt;<br>    &lt;/data&gt;<br><br>    &lt;androidx.coordinatorlayout.widget.CoordinatorLayout<br><br>      &lt;Button<br>          android:id=&quot;@+id/button&quot;<br>          android:layout_width=&quot;match_parent&quot;<br>          android:layout_height=&quot;60dp&quot;<br>          android:layout_marginStart=&quot;@dimen/dp30&quot;<br>          android:layout_marginEnd=&quot;@dimen/dp30&quot;<br>          android:layout_marginTop=&quot;200dp&quot;<br>          android:text=&quot;Show Text&quot;&gt;<br>      &lt;/Button&gt;<br>      <br>      &lt;TextView<br>          android:id=&quot;@+id/text_preview&quot;<br>          android:layout_width=&quot;match_parent&quot;<br>          android:layout_height=&quot;160dp&quot;<br>          android:layout_marginTop=&quot;300dp&quot;<br>          android:gravity=&quot;center&quot;&gt;<br>      &lt;/TextView&gt;<br><br>    &lt;/androidx.coordinatorlayout.widget.CoordinatorLayout&gt;<br><br>&lt;/layout&gt;</pre><p>Lets create a page where there is a button and Textview. The user clicks on button and text becomes visible. We need to create one <strong>onClickListener</strong> for the button in “<strong>TempViewModel</strong>”.</p><pre>package com.example.android.bluetoothlegatt.viewModel<br><br>import android.view.View<br>import androidx.lifecycle.ViewModel<br>import com.example.android.bluetoothlegatt.listener.InfosecConvListener<br><br>class TempViewModel : ViewModel() {<br><br>   fun onClickButton(view: View) {<br><br>      //Here goes logic after button clicked.<br><br>  }<br>}</pre><p>Also bind this “<strong>onClickButton</strong>” function to the xml file as given below.</p><pre>&lt;?xml version=&quot;1.0&quot; encoding=&quot;utf-8&quot;?&gt;<br>&lt;layout xmlns:android=&quot;http://schemas.android.com/apk/res/android&quot;<br>    xmlns:app=&quot;http://schemas.android.com/apk/res-auto&quot;<br>    xmlns:tools=&quot;http://schemas.android.com/tools&quot;&gt;<br><br>    &lt;data&gt;<br>        &lt;variable<br>            name=&quot;viewmodelTemp&quot;<br>            type=&quot;com.example.android.viewModel.TempViewModel&quot; /&gt;<br>    &lt;/data&gt;<br><br>    &lt;androidx.coordinatorlayout.widget.CoordinatorLayout<br><br>      &lt;Button<br>          android:id=&quot;@+id/button&quot;<br>          android:layout_width=&quot;match_parent&quot;<br>          android:layout_height=&quot;60dp&quot;<br>          android:layout_marginStart=&quot;@dimen/dp30&quot;<br>          android:layout_marginEnd=&quot;@dimen/dp30&quot;<br>          android:layout_marginTop=&quot;200dp&quot;<br>          android:onClickListener=&quot;@{viewmodelTemp::onClickButton}&quot;<br>          android:text=&quot;Show Text&quot;&gt;<br>      &lt;/Button&gt;<br>      <br>      &lt;TextView<br>          android:id=&quot;@+id/text_preview&quot;<br>          android:layout_width=&quot;match_parent&quot;<br>          android:layout_height=&quot;160dp&quot;<br>          android:layout_marginTop=&quot;300dp&quot;<br>          android:gravity=&quot;center&quot;&gt;<br>      &lt;/TextView&gt;<br><br>    &lt;/androidx.coordinatorlayout.widget.CoordinatorLayout&gt;<br><br>&lt;/layout&gt;</pre><p>We have added “onClickButton” to the xml file. Now if the button clicks the function will be called. Lets create a listener class as well to write down the main logic in the activity class.</p><p><strong>Step 4: Create Listener</strong></p><p>Create a new package named “<strong>listener</strong>” as we did earlier. and right click select <strong>New -&gt; kotlin class/file -&gt; choose listener</strong>. Name the file “<strong>TempListener</strong>”. Create a function “<strong>showText</strong>”.</p><pre>package com.example.android.listener<br><br>interface TempListener {<br><br>    fun showText() {}<br><br>}</pre><p>Now lets call the above function in our “<strong>TempViewModel”</strong> class. Make an instance of listener inside viewmodel.</p><pre>package com.example.android.bluetoothlegatt.viewModel<br><br>import android.view.View<br>import androidx.lifecycle.ViewModel<br>import com.example.android.bluetoothlegatt.listener.InfosecConvListener<br><br>class TempViewModel : ViewModel() {<br><br>    var tempListener : TempListener? = null<br><br>   fun onClickButton(view: View) {<br><br>      tempListener?.showText()<br><br>  }<br>}</pre><p>Its been a while we visited our activity class😂 . Now lets go there and write the logic such as the predefined text becomes visible to user in the textview.</p><p>Add below code to our “<strong>TempActivity.kt</strong>” activity class.</p><pre>package com.example.android<br><br>import androidx.appcompat.app.AppCompatActivity<br>import android.os.Bundle<br>import android.view.View<br>import android.view.animation.Animation<br>import android.view.animation.AnimationUtils<br>import androidx.databinding.DataBindingUtil<br>import androidx.lifecycle.ViewModelProviders<br>import com.example.android.bluetoothlegatt.backgroundserviceApiModule.infosecConvApi.CattleDetailsAPI.InfosecConv<br>import com.example.android.bluetoothlegatt.databinding.ActivityInfosecConvBinding<br>import com.example.android.bluetoothlegatt.listener.InfosecConvListener<br>import com.example.android.bluetoothlegatt.viewModel.InfosecConvViewModel<br>import com.example.android.bluetoothlegatt.viewModel.TrackerMqttViewModel<br>import kotlinx.android.synthetic.main.activity_infosec_conv.*<br><br>class TempActivity : AppCompatActivity(), TempListener {<br>    override fun onCreate(savedInstanceState: Bundle?) {<br>        super.onCreate(savedInstanceState)<br>        setContentView(R.layout.activity_temp)<br><br>        val binding : ActivityTempBinding = DataBindingUtil.setContentView(this,R.layout.activity_temp)<br>        val viewModel  = ViewModelProviders.of(this).get(TempViewModel:: class.java)<br>        binding.viewmodelTemp = viewModel<br>        viewModel.tempListener = this<br>    }<br><br>    override fun onBackPressed() {<br>        super.onBackPressed()<br>    }<br><br>    override fun showText() {<br>        if (text_preview.visibility == View.GONE) {<br>          text_preview.text = &quot;Hello&quot;<br>          text_preview.visibility = View.VISIBLE<br>        }else {<br>          text_preview.visibility = View.GONE<br>        }<br>    }<br>}</pre><p>We have added logic in “<strong>showText</strong>” function. That’s it. We have data binded our Activity class and xml file. So the flow will go like. When the button is pressed the below function will be called.</p><blockquote>“<strong>android:onClickListener=”@{viewmodelTemp::onClickButton}</strong>””</blockquote><p>Then in our viewmodel “<strong>tempListener.showText()” </strong>will trigger. In the Activity class “<strong>showText</strong>” gets called.</p><p>Now you are good to run and test your project. Please feel free to comment. Thank you.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=da2d14d00595" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Using Retrofit to upload file and some data on server in Android App.]]></title>
            <link>https://medium.com/@maheshvhatkar82/using-retrofit-to-upload-file-and-some-data-on-server-in-android-app-8549e74a357e?source=rss-4ea6661e33b4------2</link>
            <guid isPermaLink="false">https://medium.com/p/8549e74a357e</guid>
            <category><![CDATA[android-development]]></category>
            <category><![CDATA[retrofit-android-studio]]></category>
            <category><![CDATA[retrofit-upload-file]]></category>
            <dc:creator><![CDATA[Mahesh Vhatkar]]></dc:creator>
            <pubDate>Thu, 20 Jul 2023 14:30:56 GMT</pubDate>
            <atom:updated>2023-07-20T14:32:25.477Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/300/1*eZf7VJHFOq3gSj6UiDuwXg.jpeg" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/300/1*eZf7VJHFOq3gSj6UiDuwXg.jpeg" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/300/1*eZf7VJHFOq3gSj6UiDuwXg.jpeg" /></figure><p>During my recent project, I utilized the Retrofit library in my App to efficiently handle file uploads alongside additional data fields. While implementing this functionality, I encountered some challenges that I want to share with you.</p><p>I would like to begin with Retrofit library, Retrofit is a popular Android library used for making HTTP requests and handling RESTful APIs effortlessly. It simplifies the process of network communication by converting HTTP endpoints into Java interfaces with annotation-based configuration.</p><p>Consider we have to implement a code to upload file on server using Java Firstly we need to create a Retrofit client. Create a java file named “<strong>UploadFileInstance</strong>” : —</p><pre>public class UploadFileInstance {<br>    public static String BASE_URL_UPLOAD = &quot;https://xyz.com/&quot;;<br><br>    static Retrofit getRetrofit() {<br>        HttpLoggingInterceptor loggingInterceptor = new HttpLoggingInterceptor();<br>        loggingInterceptor.setLevel(HttpLoggingInterceptor.Level.BODY);<br><br>        OkHttpClient client = new OkHttpClient.Builder()<br>                .addInterceptor(loggingInterceptor)<br>                .build();<br><br>        return new Retrofit.Builder()<br>                .client(client)<br>                .baseUrl(UploadFileInstance.BASE_URL_UPLOAD)<br>                .addConverterFactory(ScalarsConverterFactory.create())<br>                .addConverterFactory(GsonConverterFactory.create())<br>                .build();<br>    }<br>}</pre><p>This class returns Retrofit client</p><p>Assume we send <strong>content-type</strong> and <strong>size</strong> along with file. Now, create an interface named <strong>“UploadFileInterface” :-</strong></p><pre>public interface UploadFileInterface {<br><br>    @Multipart<br>    @POST(&quot;upload-document&quot;)<br><br>    Call&lt;JSONObject&gt; uploadFile(<br>            @Part MultipartBody.Part file,<br>            @Part(&quot;size&quot;) RequestBody size,<br>            @Part(&quot;content-type&quot;) RequestBody contentType<br>    );<br>}</pre><p><strong>RequestBody</strong> is used to send data as JSON, plain text and even binary data. Here we are using it to send plain text. “<strong>@Multipart</strong>” is Annotation to use MultipartBody. Replace “<strong>upload-document</strong>” with your URL endpoint. <strong>&lt;JSONObject&gt;</strong> denotes the datatype you will receive as response. In my case it is JSONObject. “size” and “content-type” are name of parameters.</p><p>MultipartBody allows user to send Body along with file. Now lets code the API call.</p><p>Create a java file named <strong>“UploadFile”</strong> :-</p><pre>public class UploadFile {<br>    public static void upload(Context context, String filePath){<br><br>    File file = new File(filePath);<br><br>    // Create request body part<br>        RequestBody size = RequestBody.create(MediaType.parse(&quot;text/plain&quot;), String.valueOf(file.length()));<br>        RequestBody contentType = RequestBody.create(MediaType.parse(&quot;text/plain&quot;), &quot;application/pdf&quot;);<br><br>        // Create a multipart request body part for the file<br>        MultipartBody.Part filePart = MultipartBody.Part.createFormData(&quot;file&quot;, file.getName(), RequestBody.create(MediaType.parse(&quot;application/pdf&quot;), file));<br>        // Make the API call<br>        UploadFileInterface getResponse = UploadFileInstance.getRetrofit().create(UploadFileInterface.class);<br>        Call&lt;JSONObject&gt; call = getResponse.uploadFile(filePart, size, contentType);<br><br>// Asynchronously execute the API call<br>    call.enqueue(new Callback&lt;JSONObject&gt;() {<br>        @Override<br>        public void onResponse(Call&lt;JSONObject&gt; call, Response&lt;JSONObject&gt; response) {<br>            Log.e(&quot;Response&quot;, &quot;response --: &quot; + response.body());<br>            //Toast.makeText()<br>            if (response.isSuccessful()) {<br>                if (response.body() != null) {<br>                    Toast.makeText(context, response.body().toString(), Toast.LENGTH_SHORT).show();<br>                }<br>            } else {<br>                try {<br>                    Log.i(&quot;onEmptyResponse&quot;, &quot;Returned empty response&quot;);<br>                    Toast.makeText(context, response.errorBody().string(), Toast.LENGTH_LONG).show();<br>                } catch (Exception e ) {<br>                    e.printStackTrace();<br>                }<br>            }<br><br>        }<br><br>        @Override<br>        public void onFailure(Call&lt;JSONObject&gt; call, Throwable t) {<br>            Log.e(&quot;failure&quot;, &quot;message = &quot; + t.getMessage());<br>            Log.d(&quot;failure&quot;, &quot;cause = &quot; + t.getCause());<br>            Toast.makeText(context,t.getMessage(),Toast.LENGTH_LONG).show();<br><br><br>        }<br>    });<br>    }<br>}</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/300/1*eZf7VJHFOq3gSj6UiDuwXg.jpeg" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/300/1*eZf7VJHFOq3gSj6UiDuwXg.jpeg" /></figure><p>Now call <strong>UploadFile.upload(context, filepath)</strong> where ever you want in your Android Application.</p><p>This is how we implemented an API call using retrofit and Uploaded file to server.</p><p>I hope this will help someone, Thank you.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=8549e74a357e" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>