<?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"><channel><title><![CDATA[Blog | Vignesh Marimuthu]]></title><description><![CDATA[Android developer who loves to explore multiple domains and frameworks]]></description><link>https://blog.vigneshmarimuthu.com</link><generator>RSS for Node</generator><lastBuildDate>Sat, 11 Apr 2026 23:00:04 GMT</lastBuildDate><atom:link href="https://blog.vigneshmarimuthu.com/rss.xml" rel="self" type="application/rss+xml"/><language><![CDATA[en]]></language><ttl>60</ttl><item><title><![CDATA[OOPS with Kotlin]]></title><description><![CDATA[Kotlin is a modern, powerful, and developer-friendly language, especially for Android development. When compared with Java, it is more concise, readable, and better at handling null safety. Kotlin is a multi-paradigm language that supports both objec...]]></description><link>https://blog.vigneshmarimuthu.com/oops-with-kotlin</link><guid isPermaLink="true">https://blog.vigneshmarimuthu.com/oops-with-kotlin</guid><category><![CDATA[Kotlin]]></category><dc:creator><![CDATA[Vignesh Marimuthu]]></dc:creator><pubDate>Sun, 09 Mar 2025 09:06:22 GMT</pubDate><enclosure url="https://cdn.hashnode.com/res/hashnode/image/stock/unsplash/azJJSiwWW90/upload/f1346d034214ec802cb0ec2583f4908c.jpeg" length="0" type="image/jpeg"/><content:encoded><![CDATA[<p>Kotlin is a modern, powerful, and developer-friendly language, especially for Android development. When compared with Java, it is more concise, readable, and better at handling null safety. Kotlin is a multi-paradigm language that supports both object-oriented programming (OOP) and functional programming features.</p>
<p>Let us look into the OOP side of Kotlin and how to implement the four great pillars of OOP</p>
<h2 id="heading-pillars-of-oop">Pillars of OOP</h2>
<ol>
<li><p>Encapsulation</p>
</li>
<li><p>Abstraction</p>
</li>
<li><p>Polymorphism</p>
</li>
<li><p>Inheritance</p>
</li>
</ol>
<h3 id="heading-encapsulation">Encapsulation</h3>
<blockquote>
<p>the bundling of data (variables) and methods (functions) that operate on the data into a single unit. Restricts access to some attributes and exposes only necessary attributes for modification</p>
</blockquote>
<p>Kotlin provides access modifiers like <em>private</em>, <em>public</em>, <em>internal</em>, and <em>protected</em> to control exposing access to attributes for modification.</p>
<pre><code class="lang-kotlin"><span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">User</span> </span>{
    <span class="hljs-keyword">private</span> <span class="hljs-keyword">var</span> password: String = <span class="hljs-string">"secret"</span> <span class="hljs-comment">// password cannot be directly modified. </span>

    <span class="hljs-function"><span class="hljs-keyword">fun</span> <span class="hljs-title">setPassword</span><span class="hljs-params">(newPassword: <span class="hljs-type">String</span>)</span></span> {
        <span class="hljs-comment">// add any validation here if required, before making any modification</span>
        password = newPassword
    }

    <span class="hljs-function"><span class="hljs-keyword">fun</span> <span class="hljs-title">getPassword</span><span class="hljs-params">()</span></span>: String {
       <span class="hljs-comment">// add any validation here if required, before returning the password value</span>
       <span class="hljs-keyword">return</span> <span class="hljs-string">"****"</span>  <span class="hljs-comment">// Hiding actual password</span>
    }
}
</code></pre>
<h3 id="heading-abstraction">Abstraction</h3>
<blockquote>
<p>hides implementation details and only exposes relevant functionalities. This allows interacting with objects without needing to understand the complex inner workings.</p>
</blockquote>
<p>In Kotlin, abstraction can be achieved in two ways. Abstract class and Interfaces.</p>
<h4 id="heading-abstract-class">Abstract Class</h4>
<pre><code class="lang-kotlin"><span class="hljs-keyword">abstract</span> <span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">Vehicle</span> </span>{
    <span class="hljs-keyword">abstract</span> <span class="hljs-function"><span class="hljs-keyword">fun</span> <span class="hljs-title">start</span><span class="hljs-params">()</span></span>  <span class="hljs-comment">// No implementation</span>
}

<span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">Car</span> : <span class="hljs-type">Vehicle</span></span>() {
    <span class="hljs-keyword">override</span> <span class="hljs-function"><span class="hljs-keyword">fun</span> <span class="hljs-title">start</span><span class="hljs-params">()</span></span> {
        println(<span class="hljs-string">"Car is starting..."</span>)
    }
}
</code></pre>
<h4 id="heading-interface">Interface</h4>
<pre><code class="lang-kotlin"><span class="hljs-class"><span class="hljs-keyword">interface</span> <span class="hljs-title">Clickable</span> </span>{
    <span class="hljs-function"><span class="hljs-keyword">fun</span> <span class="hljs-title">click</span><span class="hljs-params">()</span></span>
}

<span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">Button</span> : <span class="hljs-type">Clickable {</span></span>
    <span class="hljs-keyword">override</span> <span class="hljs-function"><span class="hljs-keyword">fun</span> <span class="hljs-title">click</span><span class="hljs-params">()</span></span> {
        println(<span class="hljs-string">"Button clicked!"</span>)
    }
}
</code></pre>
<p>The major difference between an abstract class and an interface is that an abstract class can have both concrete methods and abstract methods, whereas interfaces cannot have method implementations. If you require to have functions that are not mandatory for the child class to implement or override, you can use an abstract class instead of an interface.</p>
<h3 id="heading-inheritance">Inheritance</h3>
<blockquote>
<p>allows a class (child) to inherit the properties and behaviours of another class (parent)</p>
</blockquote>
<p>In Kotlin, you can extend a class if it is <strong><em>open.</em></strong></p>
<pre><code class="lang-kotlin"><span class="hljs-keyword">open</span> <span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">Animal</span> </span>{
    <span class="hljs-function"><span class="hljs-keyword">fun</span> <span class="hljs-title">eat</span><span class="hljs-params">()</span></span> {
        println(<span class="hljs-string">"munch munch munch..."</span>)
    }
}

<span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">Dog</span> : <span class="hljs-type">Animal</span></span>() {
    <span class="hljs-function"><span class="hljs-keyword">fun</span> <span class="hljs-title">bark</span><span class="hljs-params">()</span></span> = println(<span class="hljs-string">"Barking..."</span>)
}

<span class="hljs-function"><span class="hljs-keyword">fun</span> <span class="hljs-title">main</span><span class="hljs-params">()</span></span> {
    <span class="hljs-keyword">val</span> dog = Dog()
    dog.eat()  <span class="hljs-comment">// Inherited from Animal</span>
    dog.bark()
}
</code></pre>
<p>One important thing to notice is that Kotlin <strong>does not</strong> support multiple inheritance by classes due to the complexity and ambiguity it can introduce. Read <a target="_blank" href="https://en.wikipedia.org/wiki/Multiple_inheritance">Diamond Problem</a> if you want to learn more about the ambiguity. But in Kotlin, you can inherit multiple interfaces.</p>
<pre><code class="lang-kotlin"><span class="hljs-class"><span class="hljs-keyword">interface</span> <span class="hljs-title">CookingSkill</span> </span>{
    <span class="hljs-function"><span class="hljs-keyword">fun</span> <span class="hljs-title">makeBeefCurry</span><span class="hljs-params">()</span></span>
    <span class="hljs-function"><span class="hljs-keyword">fun</span> <span class="hljs-title">makeChickenTikka</span><span class="hljs-params">()</span></span>
}

<span class="hljs-class"><span class="hljs-keyword">interface</span> <span class="hljs-title">BakingSkill</span> </span>{
    <span class="hljs-function"><span class="hljs-keyword">fun</span> <span class="hljs-title">makeCheeseCake</span><span class="hljs-params">()</span></span>
}

<span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">Chef</span> : <span class="hljs-type">CookingSkill</span>, <span class="hljs-type">BakingSkill {</span></span>
    <span class="hljs-keyword">override</span> <span class="hljs-function"><span class="hljs-keyword">fun</span> <span class="hljs-title">makeBeefCurry</span><span class="hljs-params">()</span></span> {
        TODO(<span class="hljs-string">"Not yet implemented"</span>)
    }

    <span class="hljs-keyword">override</span> <span class="hljs-function"><span class="hljs-keyword">fun</span> <span class="hljs-title">makeChickenTikka</span><span class="hljs-params">()</span></span> {
        TODO(<span class="hljs-string">"Not yet implemented"</span>)
    }

    <span class="hljs-keyword">override</span> <span class="hljs-function"><span class="hljs-keyword">fun</span> <span class="hljs-title">makeTiramisu</span><span class="hljs-params">()</span></span> {
        TODO(<span class="hljs-string">"Not yet implemented"</span>)
    }

}
</code></pre>
<h3 id="heading-polymorphism">Polymorphism</h3>
<blockquote>
<p>allows a single function or method to have multiple behaviors depending on the object calling it.</p>
</blockquote>
<p>Kotlin supports both method overriding and method overloading polymorphism.</p>
<h4 id="heading-method-overriding">Method Overriding</h4>
<p>In Kotlin, to override a method, it is required to be explicitly mentioned as an <strong><em>open</em></strong> method.</p>
<pre><code class="lang-kotlin"><span class="hljs-keyword">open</span> <span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">Animal</span> </span>{
    <span class="hljs-keyword">open</span> <span class="hljs-function"><span class="hljs-keyword">fun</span> <span class="hljs-title">makeSound</span><span class="hljs-params">()</span></span> {
        println(<span class="hljs-string">"Making sound..."</span>)
    }
}

<span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">Dog</span> : <span class="hljs-type">Animal</span></span>() {
    <span class="hljs-keyword">override</span> <span class="hljs-function"><span class="hljs-keyword">fun</span> <span class="hljs-title">makeSound</span><span class="hljs-params">()</span></span> {
        println(<span class="hljs-string">"Woof..."</span>)
    }
}

<span class="hljs-function"><span class="hljs-keyword">fun</span> <span class="hljs-title">main</span><span class="hljs-params">()</span></span> {
    <span class="hljs-keyword">val</span> dog = Dog()
    dog.makeSound()
}
</code></pre>
<p><strong>Output:</strong></p>
<pre><code class="lang-bash"> Woof...
</code></pre>
<h4 id="heading-method-overloading">Method Overloading</h4>
<pre><code class="lang-kotlin"><span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">SumCalculations</span> </span>{
    <span class="hljs-function"><span class="hljs-keyword">fun</span> <span class="hljs-title">add</span><span class="hljs-params">(a: <span class="hljs-type">Int</span>, b: <span class="hljs-type">Int</span>)</span></span>: <span class="hljs-built_in">Int</span> {
        <span class="hljs-keyword">return</span> a + b
    }

    <span class="hljs-function"><span class="hljs-keyword">fun</span> <span class="hljs-title">add</span><span class="hljs-params">(a: <span class="hljs-type">Double</span>, b: <span class="hljs-type">Double</span>)</span></span>: <span class="hljs-built_in">Double</span> {
        <span class="hljs-keyword">return</span> a + b
    }
}

<span class="hljs-function"><span class="hljs-keyword">fun</span> <span class="hljs-title">main</span><span class="hljs-params">()</span></span> {
    <span class="hljs-keyword">val</span> sumCalculations = SumCalculations()
    <span class="hljs-keyword">val</span> firstOutput = sumCalculations.add(<span class="hljs-number">1</span>,<span class="hljs-number">2</span>) 
    <span class="hljs-keyword">val</span> secondOutput = sumCalculations.add(<span class="hljs-number">1.1</span>,<span class="hljs-number">2.2</span>) 
}
</code></pre>
<hr />
<p>Follow for more such posts on Kotlin and Android development.</p>
]]></content:encoded></item><item><title><![CDATA[Calculate distance between current location and Polyline Data in Flutter]]></title><description><![CDATA[Consider a River that goes in length of many kilometers. Now, if I ask you how do you detect whether the user is standing close to the river, what would be your answer?
Breakdown
Now, let's break down our problem into parts. If we need to calculate t...]]></description><link>https://blog.vigneshmarimuthu.com/calculate-distance-between-current-location-and-polyline-data-in-flutter</link><guid isPermaLink="true">https://blog.vigneshmarimuthu.com/calculate-distance-between-current-location-and-polyline-data-in-flutter</guid><category><![CDATA[Android]]></category><category><![CDATA[Flutter]]></category><category><![CDATA[Geospatial]]></category><category><![CDATA[geolocation]]></category><dc:creator><![CDATA[Vignesh Marimuthu]]></dc:creator><pubDate>Mon, 22 Jul 2024 12:43:01 GMT</pubDate><enclosure url="https://cdn.hashnode.com/res/hashnode/image/stock/unsplash/1tpLdmxki-c/upload/d5121f5fab365e252e3d2829f21aad34.jpeg" length="0" type="image/jpeg"/><content:encoded><![CDATA[<p><em>Consider a River that goes in length of many kilometers. Now, if I ask you how do you detect whether the user is standing close to the river, what would be your answer?</em></p>
<h2 id="heading-breakdown">Breakdown</h2>
<p>Now, let's break down our problem into parts. If we need to calculate the distance between two locations, we can use the Haversine Formula to manually calculate the distance or the GeoLocator dependency, which has a built-in function to calculate the distance in units between two points.</p>
<p>But what if we have one location point but the other is a array of location points. How do we calculate whether the provided location point is closer to any of the location points provided. To do that, we need to understand polyline concept.</p>
<h2 id="heading-polyline">Polyline</h2>
<p><strong>A polyline is a series of connected line segments on a map.</strong> It's essentially a path drawn between multiple points. This is commonly used to visualize routes, trails, or any other linear data on a map.</p>
<p><img src="https://media.geeksforgeeks.org/wp-content/uploads/20210706172224/Screenshot20210706171629MyApplication2.jpg" alt="Picture explaining polyline" /></p>
<p>So, a polyline is a line drawn between two latitude-longitude points. A route from point A to point B will have 'n' number of location points and therefore 'n' number of polylines, where 'n' depends on the number of straight lines needed to reach the destination.</p>
<h2 id="heading-approach">Approach</h2>
<p><em><mark>We take pairs of location points and draw polyline between them. And then take the target location point and find a projected location point that falls right on the polyline. Then we will calculate the distance between target location point and the projected point.</mark></em></p>
<p>Consider the following example. Let us take the first two location points (L0, L1) in the given array and draw polyline between them. We have the target location (current location) somewhere in the top of the polyline.</p>
<p>We can now draw a line from the target location point, perpendicular (or shortest distance) to the polyline to find the projected point that touches the polyline. Now we have the projected point location and target point location. We can easily calculate distance between these two using geolocator.</p>
<h2 id="heading-code">Code</h2>
<p>Taken in consideration that you have already included geo_locator dependency in your package. Lets create two data classes named <em>'line_segment.dart'</em> and <em>'location_info.dart'</em></p>
<pre><code class="lang-dart"><span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">LineSegment</span> </span>{
  <span class="hljs-keyword">final</span> LocationInfo start;
  <span class="hljs-keyword">final</span> LocationInfo end;

  LineSegment(<span class="hljs-keyword">this</span>.start, <span class="hljs-keyword">this</span>.end);
}
</code></pre>
<pre><code class="lang-dart"><span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">LocationInfo</span> </span>{
  <span class="hljs-keyword">final</span> <span class="hljs-built_in">double</span> latitude;
  <span class="hljs-keyword">final</span> <span class="hljs-built_in">double</span> longitude;

  LocationInfo({<span class="hljs-keyword">required</span> <span class="hljs-keyword">this</span>.latitude, <span class="hljs-keyword">this</span>.longitude});  
}
</code></pre>
<p>Now, lets create a helper class named <em>'location_service.dart'</em> with the following function added. The function will take two parameters. One is the user location called <strong>point</strong> and another is a <strong>LineSegment</strong> parameter which contains start and end lat long. The function will draw a line between start and end positions and project another line to reach the previously drawn line. This projection will happen in such a way to find the shortest path to reach the previously drawn line. The function will then return the co-ordinates of the projected point.</p>
<pre><code class="lang-dart"><span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">LocationService</span> </span>{
  LocationInfo _projectPointOnLineSegment(
      LocationInfo point, LineSegment lineSegment) {
    <span class="hljs-comment">// Vector from line segment start to point</span>
    <span class="hljs-keyword">final</span> v = LocationInfo(
        latitude: point.latitude - lineSegment.start.latitude,
        longitude: point.longitude - lineSegment.start.longitude);

    <span class="hljs-comment">// Vector representing the line segment</span>
    <span class="hljs-keyword">final</span> w = LocationInfo(
        latitude: lineSegment.end.latitude - lineSegment.start.latitude,
        longitude: lineSegment.end.longitude - lineSegment.start.longitude);

    <span class="hljs-comment">// Calculate the projection parameter</span>
    <span class="hljs-keyword">final</span> wLengthSquared = w.latitude * w.latitude + w.longitude * w.longitude;
    <span class="hljs-keyword">final</span> wDotV = w.latitude * v.latitude + w.longitude * v.longitude;
    <span class="hljs-keyword">final</span> t = wDotV / wLengthSquared;

    <span class="hljs-comment">// Clamp t to the range [0, 1] to ensure the projected point is on the line segment</span>
    <span class="hljs-keyword">final</span> tClamped = t.clamp(<span class="hljs-number">0.0</span>, <span class="hljs-number">1.0</span>);

    <span class="hljs-comment">// Calculate the projected point</span>
    <span class="hljs-keyword">final</span> projectedPoint = LocationInfo(
      latitude: lineSegment.start.latitude + tClamped * w.latitude,
      longitude: lineSegment.start.longitude + tClamped * w.longitude,
    );

    <span class="hljs-keyword">return</span> projectedPoint;
  }
}
</code></pre>
<p>Now that we have found out the co-ordinates of a projected point, we can easily calculate the distance between projected point and the user's current location using geo_locator. Add the following functions inside <em>'location_service.dart'</em></p>
<pre><code class="lang-dart">  <span class="hljs-built_in">double</span> calculateDistanceToRoad(
      LineSegment lineSegment, LocationInfo currentLoc) {

    <span class="hljs-comment">// finds the co-ordinates of projected point   </span>
    LocationInfo projectLoc =
        _projectPointOnLineSegment(currentLoc, lineSegment);

    <span class="hljs-comment">// Calculate distance between current location and projection point</span>
    <span class="hljs-keyword">final</span> distanceToProjection =
        calculateDistanceInMeters(currentLoc, projectLoc);
  } 

  <span class="hljs-built_in">double</span> calculateDistanceInMeters(LocationInfo startDes, LocationInfo endDes) {
    <span class="hljs-keyword">return</span> _geoLocator.distanceBetween(startDes.latitude, startDes.longitude,
        endDes.latitude, endDes.longitude);
  }
</code></pre>
<blockquote>
<p>If you have a use case where you have a large list of polyline points, and want to detect whether the user is in a certain distance from the entire route, you can loop through each co-ordinate pairs to find the distance from user location and validate whether the calculated distance is less than the desired radius.  </p>
<p>Thank you for reading!</p>
</blockquote>
]]></content:encoded></item><item><title><![CDATA[Interview Preparation Kit for Senior Android Developers]]></title><description><![CDATA[A typical job interview is a discussion between two liars

Interviews are a headache in general. No matter where you stand in the experience scale, it comes with lot of self doubts, impostor syndromes, preparation burdens and what not. Especially whe...]]></description><link>https://blog.vigneshmarimuthu.com/interview-preparation-kit-for-senior-android-developers</link><guid isPermaLink="true">https://blog.vigneshmarimuthu.com/interview-preparation-kit-for-senior-android-developers</guid><category><![CDATA[android app development]]></category><category><![CDATA[interview questions]]></category><category><![CDATA[interview preparations]]></category><category><![CDATA[Android]]></category><dc:creator><![CDATA[Vignesh Marimuthu]]></dc:creator><pubDate>Wed, 29 Nov 2023 06:25:39 GMT</pubDate><enclosure url="https://cdn.hashnode.com/res/hashnode/image/stock/unsplash/gySMaocSdqs/upload/334aa6a28ca17512e686fac130a8bcd9.jpeg" length="0" type="image/jpeg"/><content:encoded><![CDATA[<blockquote>
<p>A typical job interview is a discussion between two liars</p>
</blockquote>
<p>Interviews are a headache in general. No matter where you stand in the experience scale, it comes with lot of self doubts, impostor syndromes, preparation burdens and what not. Especially when you are a experienced developer, somehow the companies are expecting us to be well equipped to solve all the world problems.</p>
<p>Not sure about how to solve all world problems, but I am preparing a questionnaire for Senior Android Developers with around 5 years of technical experience. This is for myself and might be useful to you.</p>
<p>Planning to split the article into multiple parts, grouped based on topics. I guess this approach would help us to practice and revise in specific to topics. Feel free to comment suggestions and correct my mistakes if you find any.</p>
<hr />
<h1 id="heading-android-core-questions">Android Core Questions</h1>
<h3 id="heading-explain-activity-life-cycle"><strong>Explain activity life-cycle</strong></h3>
<p><img src="https://developer.android.com/guide/components/images/activity_lifecycle.png" alt /></p>
<h3 id="heading-explain-fragment-life-cycle"><strong>Explain fragment life-cycle</strong></h3>
<p><img src="https://developer.android.com/static/images/guide/fragments/fragment-view-lifecycle.png" alt /></p>
<h3 id="heading-what-is-context-in-android"><strong>What is context in Android?</strong></h3>
<ul>
<li><p>In Android, Context is an important and fundamental class that provides access to various <mark>application-specific resources</mark> and information about the application environment.</p>
</li>
<li><p>It's an abstract class provided by the Android framework, and several classes within Android, such as Activities, Services, Application, and Broadcast Receivers, extend or implement the Context class.</p>
</li>
<li><p>It is used to access app specific resources, Files and database, Location Manager, Audio Manager, retrieve info about app package (version number, package name), view inflation, access theme, initiate service, broadcast, start Activity</p>
</li>
</ul>
<h3 id="heading-what-are-the-different-types-of-context-in-android"><strong>What are the different types of Context in Android?</strong></h3>
<p>In Android, there are several types of Context available, each serving specific purposes or contexts within an application. These various Context types are differentiated based on their scope and the environment they provide access to:</p>
<ul>
<li><p><strong>Application Context (</strong><code>ApplicationContext</code><strong>)</strong>:</p>
<ol>
<li><p>Obtained via <code>getApplicationContext()</code></p>
</li>
<li><p>Represents the application's entire life-cycle.</p>
</li>
<li><p>Exists throughout the application's lifetime.</p>
</li>
<li><p>Should be used when an object needs access to application-level resources or global application state. For example, retrieving resources, accessing the application's package information, or using system services.</p>
</li>
<li><p>Be cautious not to store long-lived references to UI components (like Activities or Views) within the Application Context to prevent memory leaks.</p>
</li>
</ol>
</li>
<li><p><strong>Activity Context (</strong><code>ActivityContext</code><strong>)</strong>:</p>
<ol>
<li><p>Obtained via <code>this</code> or <code>getActivity()</code>.</p>
</li>
<li><p>Represents the current state of an Activity.</p>
</li>
<li><p>Exists as long as the activity is alive.</p>
</li>
<li><p>Should be used when working with UI components (Views, Dialogs) or accessing resources that are tied to a particular activity, like inflating layouts or creating intents.</p>
</li>
<li><p>Be careful not to pass the Activity Context beyond the lifetime of the activity (e.g., storing it in long-lived objects) to avoid memory leaks.</p>
</li>
</ol>
</li>
<li><p><strong>Service Context (</strong><code>ServiceContext</code><strong>)</strong>:</p>
<ol>
<li><p>Obtained via <code>this</code> within a Service.</p>
</li>
<li><p>Represents the context of a running Service.</p>
</li>
<li><p>Exists as long as the service is running.</p>
</li>
<li><p>Used within services for operations like interacting with system services, accessing resources, or managing service-related tasks.</p>
</li>
</ol>
</li>
<li><p><strong>Broadcast Receiver Context (</strong><code>ReceiverContext</code><strong>)</strong>:</p>
<ol>
<li><p>Obtained via <code>onReceive()</code> method in a Broadcast Receiver.</p>
</li>
<li><p>Represents the context of a broadcast being received.</p>
</li>
<li><p>Exists during the execution of the <code>onReceive()</code> method.</p>
</li>
<li><p>Used within Broadcast Receivers for handling broadcast intents, starting services, etc.</p>
</li>
</ol>
</li>
<li><p><strong>Content Provider Context (</strong><code>ContentProviderContext</code><strong>)</strong>:</p>
<ol>
<li><p>Obtained via <code>getContext()</code> in a Content Provider.</p>
</li>
<li><p>Represents the context of a Content Provider.</p>
</li>
<li><p>Exists during the execution of Content Provider methods.</p>
</li>
<li><p>Used within Content Providers for accessing and manipulating data through the Content Resolver.</p>
</li>
</ol>
</li>
</ul>
<h3 id="heading-what-are-broadcast-receiver"><strong>What are Broadcast Receiver?</strong></h3>
<ul>
<li><p>Broadcast Receivers in Android are components that facilitate communication between different parts of an application or between different applications.</p>
</li>
<li><p>They are particularly useful for responding to system-wide broadcast announcements made by the Android system or other applications. Battery Status Change, Network Changes, Push Notifications, Alarm Managers, Background Operations and scheduled tasks, Triggering UI components.</p>
</li>
</ul>
<h3 id="heading-what-are-intents"><strong>What are intents?</strong></h3>
<p>In Android, Intents are a fundamental part of the operating system that enables communication between components such as activities, services, broadcast receivers, and content providers. There are mainly three types of Intents</p>
<ul>
<li><p>Implicit Intent</p>
</li>
<li><p>Explicit Intent</p>
</li>
<li><p>Pending Intent</p>
</li>
</ul>
<h3 id="heading-explain-different-types-of-intents"><strong>Explain different types of Intents</strong></h3>
<p>Explicit Intent : Used to launch components within the same application by explicitly specifying the target component's name (i.e., its class name)</p>
<pre><code class="lang-java">Intent intent = <span class="hljs-keyword">new</span> Intent(CurrentActivity.<span class="hljs-keyword">this</span>, TargetActivity.class); 
startActivity(intent);
</code></pre>
<p>Implicit Intent : Used to activate components (like activities, services, or broadcast receivers) without specifying the exact class name of the component to be invoked. (opening a link in browser)</p>
<pre><code class="lang-java">Intent intent = <span class="hljs-keyword">new</span> Intent(Intent.ACTION_VIEW, Uri.parse(<span class="hljs-string">"https://www.example.com"</span>)); 
startActivity(intent);
</code></pre>
<p>Pending Intent : Used in scenarios where an operation needs to be performed at a later time, such as sending a notification or scheduling an alarm, and the operation is triggered from a different context than where it will be executed. Pending Intents are a type of intent that allows you to pass a token representing a future execution of a specified intent.</p>
<pre><code class="lang-java">Intent notificationIntent = <span class="hljs-keyword">new</span> Intent(context, TargetActivity.class); 
PendingIntent pendingIntent = PendingIntent.getActivity(context, requestCode, 
                                    notificationIntent, PendingIntent.FLAG_UPDATE_CURRENT);
</code></pre>
<h3 id="heading-is-it-possible-to-create-activity-without-ui"><strong>Is it possible to create activity without UI?</strong></h3>
<p>Yes it is possible. You simply need to remove UI initialisation in onCreate method.</p>
<h3 id="heading-what-is-anr-in-android"><strong>What is ANR in android?</strong></h3>
<ul>
<li><p>ANR occurs when the user interface thread (main thread or UI thread) of an Android application is blocked for an extended period, typically around 5 seconds or more, causing the app to become unresponsive to user interactions.</p>
</li>
<li><p>Common causes of ANR include: - Lengthy operations performed on the UI thread, such as long-running computations, network operations, or database queries.</p>
</li>
<li><p>Deadlocks or race conditions that lead to thread contention, causing the UI thread to halt.</p>
</li>
</ul>
<h3 id="heading-what-are-crashes-in-android">What are crashes in Android?</h3>
<ul>
<li><p>Crashes in Android applications occur when the app encounters an unrecoverable error or exception during runtime, leading to the app's termination.</p>
</li>
<li><p>Null Pointer Exceptions (NPEs), ArrayIndexOutOfBoundsException, or other unchecked exceptions.</p>
</li>
</ul>
<h3 id="heading-how-to-avoid-anr-in-android"><strong>How to avoid ANR in Android</strong></h3>
<ul>
<li><p>Offload Long-Running Operations from the UI Thread</p>
</li>
<li><p>Use Loaders or AsyncTasks Carefully</p>
</li>
<li><p>Avoid Network Operations on the Main Thread </p>
</li>
<li><p>Optimise Database Access </p>
</li>
<li><p>Use Handler Threads Wisely </p>
</li>
<li><p>Use Profiling Tools</p>
</li>
</ul>
<h3 id="heading-what-is-the-purposes-of-service-in-android">What is the purposes of Service in Android?</h3>
<p>Android Service is used to perform long running jobs off the UI thread. A typical long running tasks can be periodic downloading of data from internet, saving multiple records into database, perform file I/O, fetching your phone contacts list, etc. For such long running tasks, Service is used to avoid UI lags and makes user experience better.</p>
<h3 id="heading-what-is-the-difference-between-bound-and-unbounded-service"><strong>What is the difference between bound and unbounded service?</strong></h3>
<ul>
<li><p><strong>Bound Service –</strong> Service which call indefinitely in between activity. An Android component may bind itself to a Service using bindservice (). A bound service would run as long as the other application components are bound to it. As soon as they unbind, the service destroys itself.</p>
</li>
<li><p><strong>Unbound Service –</strong> Service which call at the life span of calling activity. In this case, an application component starts the service, and it would continue to run in the background, even if the original component that initiated it is destroyed. For instance, when started, a service would continue to play music in the background indefinitely.</p>
</li>
</ul>
<h3 id="heading-how-can-we-make-the-alarmservice-run-forever-even-after-device-reboot"><strong>How can we make the AlarmService run forever even after device reboot?</strong></h3>
<p>Once you start an AlarmService, it runs forever until your device restarts. Once your device restart, you have to start the service explicitly to run it forever again. You have to register BroadcastReceiver to handle boot event.</p>
<h3 id="heading-what-are-the-key-differences-between-a-service-and-intentservice-in-android"><strong>What are the key differences between a service and IntentService in Android?</strong></h3>
<div class="hn-table">
<table>
<thead>
<tr>
<td><strong>Service</strong></td><td><strong>IntentService</strong></td></tr>
</thead>
<tbody>
<tr>
<td>Service can be used in tasks with no UI, but shouldn’t be too long. If you need to perform long tasks, you must create a new thread with in Service</td><td>IntentService can be used in long running tasks usually with no communication to Main Thread. If communication is required, can use Main Thread handler or broadcast intents.</td></tr>
<tr>
<td>Service can be started using startService() method</td><td>IntentService can be started using startService() method and it triggers onHandleIntent() method.</td></tr>
<tr>
<td>Service can be triggered from any thread</td><td>IntentService must be triggered from Main Thread</td></tr>
<tr>
<td>The Service may block the Main Thread of the application.</td><td>The IntentService cannot run tasks in parallel. Hence all the consecutive intents will go into the message queue for the worker thread and will execute sequentially.</td></tr>
<tr>
<td>You must call stopSelf() or stopService() to stop a service once your its job is done.</td><td>IntentService stops itself when it finishes its job so you never have to call stopSelf()</td></tr>
</tbody>
</table>
</div><h3 id="heading-what-is-the-importance-of-the-androidmanifestxml-file-in-an-android-application"><strong>What is the importance of the AndroidManifest.xml file in an Android application?</strong></h3>
<p>The AndroidManifest.xml file is a key component of an Android application. It is an XML file that provides essential information about the application to the Android operating system. Some of the important roles that the AndroidManifest.xml file in the Android SDK plays are:</p>
<ul>
<li><p><strong>Declaring the application's package name:</strong> The package name is a unique identifier for the application, and it is used to distinguish it from other applications installed on the device.</p>
</li>
<li><p><strong>Declaring the application's components:</strong> The manifest file declares all the components of the application, including activities, services, broadcast receivers, and content providers. The Android OS uses this information to launch and manage these components.</p>
</li>
<li><p><strong>Declaring the required permissions:</strong> The AndroidManifest.xml file lists all the permissions that the application requires to access system resources or other applications' data. When the application is installed, users are prompted to grant these permissions.</p>
</li>
<li><p><strong>Declaring the application's minimum and target API levels:</strong> The manifest file specifies the application's minimum Android API level required to run and the target API level the application is built for.</p>
</li>
<li><p><strong>Declaring the application's launch activity:</strong> The manifest file specifies which activity should be launched when the application is launched.</p>
</li>
</ul>
<h2 id="heading-how-do-you-handle-configuration-changes-like-screen-rotations-in-an-android-application"><strong>How do you handle configuration changes like screen rotations in an Android application?</strong></h2>
<p>When a configuration change occurs in an Android application, such as a screen rotation or a language change, the Android system destroys and recreates the activity. This process can lead to loss of data and affect the user experience. To handle configuration changes in an Android platform, you can use one or more of the following techniques:</p>
<ul>
<li><p><strong>Save and restore instance state:</strong> The onSaveInstanceState() method of the activity is called before the activity is destroyed. You can use this method to save the current state of the activity, such as the values of UI components or any other important data, in a bundle object. The bundle is then passed to the onCreate() method of the activity when it is recreated, and you can use the values from the bundle to restore the state of the activity.</p>
</li>
<li><p><strong>Use the ViewModel:</strong> ViewModel is a component of the Android Architecture Components library that helps you to manage UI-related data in a life-cycle-conscious way. You can store the data in the ViewModel, and it will survive configuration changes because it is not tied to the activity's life cycle.</p>
</li>
<li><p><strong>Handle configuration changes manually:</strong> You can prevent the activity from being destroyed and recreated on configuration changes by specifying the android:configChanges attribute in the activity tag of the AndroidManifest.xml file. This attribute tells the system to handle the configuration change manually, and the activity's onConfigurationChanged() method will be called instead of the recreated activity.</p>
</li>
</ul>
<h2 id="heading-what-dialog-boxes-are-supported-on-android"><strong>What dialog boxes are supported on Android?</strong></h2>
<p>Android provides several types of dialog boxes that you can use to interact with users and display important information. Here are some commonly used dialog box types supported on Android:</p>
<ul>
<li><p><strong>AlertDialog:</strong> AlertDialog is a versatile dialog box that can display a title, message, and optional buttons. It is often used to prompt users for confirmation, display important information, or ask for user input.</p>
</li>
<li><p><strong>ProgressDialog:</strong> ProgressDialog is a dialog box that shows the progress of a long-running operation. It typically displays a spinning progress indicator and an optional message to inform the user about the ongoing task.</p>
</li>
<li><p><strong>DatePickerDialog:</strong> DatePickerDialog allows users to select a date from a calendar. It provides a calendar interface for choosing a specific date and returns the selected date to the application.</p>
</li>
<li><p><strong>TimePickerDialog:</strong> TimePickerDialog allows users to select a time from a clock interface. It provides a clock-like interface for choosing hours and minutes and returns the selected time to the application.</p>
</li>
<li><p><strong>BottomSheetDialog:</strong> BottomSheetDialog is a dialog that slides up from the bottom of the screen, partially covering the content. It is commonly used for displaying additional options or actions related to the current context.</p>
</li>
<li><p><strong>Custom Dialogs:</strong> Android also allows you to create custom dialog boxes by extending the Dialog or DialogFragment class. This gives you full control over the appearance and behavior of the dialog, allowing you to design a dialog that suits your specific needs.</p>
</li>
</ul>
<h2 id="heading-how-do-you-handle-background-tasks-in-an-android-application"><strong>How do you handle background tasks in an Android application?</strong></h2>
<p>There are several ways to handle background tasks in an Android application, depending on the nature of the task and the requirements of the application. Here are some commonly used methods:</p>
<ul>
<li><p><strong>Service:</strong> A service is a component in the Android system that runs in the background and performs long-running operations, such as playing music, downloading large files, or performing network requests. A service can run indefinitely or be started and stopped on demand.</p>
</li>
<li><p><strong>IntentService:</strong> An IntentService is a type of service that can handle multiple requests on a separate worker thread in a queue. It is suitable for handling long-running tasks in the background, such as downloading large files, and it automatically stops itself when the task is completed.</p>
</li>
<li><p><strong>JobScheduler:</strong> The JobScheduler is a system service introduced in Android 5.0 Lollipop that allows you to schedule background tasks to run at specific times or conditions, such as when the device is idle or connected to a charger. It is suitable for performing periodic or recurring tasks, such as syncing data or sending notifications.</p>
</li>
<li><p><strong>WorkManager:</strong> The WorkManager is a library introduced in Android Jetpack that provides a simple and flexible way to schedule and manage background tasks in your app. It automatically chooses the best implementation based on the device's API level, battery level, and network status.</p>
</li>
</ul>
<h2 id="heading-what-is-the-difference-between-a-service-and-a-broadcast-receiver-in-android"><strong>What is the difference between a service and a broadcast receiver in Android?</strong></h2>
<p>A service and a broadcast receiver are components in the Android operating system that perform background tasks but differ in their functions and how they are used.</p>
<p>A service in the Android system runs in the background and performs long-running operations, such as downloading files, playing music, or performing network requests. A service can run indefinitely or be started and stopped on demand. Services can be started in two ways: started services and bound services. A started service runs in the background until it completes its task or is stopped, while a bound service runs only as long as a client is bound to it.</p>
<p>On the other hand, a broadcast receiver is a component in the Android system that listens for system-wide broadcast events, such as the battery level changing, a phone call being received, or a new SMS message being received. When an event occurs, the broadcast receiver is notified and can perform some action in response, such as displaying a notification or starting a service.</p>
<p>In summary, the main difference between a service and a broadcast receiver is that a service is used to perform long-running background tasks. In contrast, a broadcast receiver listens to system-wide broadcast events and performs actions in response to them. Services can be started and stopped on demand, while broadcast receivers always listen to events.</p>
<hr />
<p>Resources that were helpful:<br /><a target="_blank" href="https://anywhere.epam.com/en/blog/advanced-android-interview-questions-answers">https://anywhere.epam.com/en/blog/advanced-android-interview-questions-answers</a><br /><a target="_blank" href="https://stacktips.com/articles/android-service-interview-questions">https://stacktips.com/articles/android-service-interview-questions</a></p>
<hr />
<p>The above section is only for Android Core related questions. More questionnaire on topics like Kotlin, Async Programming, Jetpack Components, Test driven will be coming up soon. Feel free to comment down if I have missed out any important questions on this topic.</p>
]]></content:encoded></item><item><title><![CDATA[Rebuilding my personal Blog]]></title><description><![CDATA[Visit my blog here. If you see everything working fine, then I must have done everything that I wanted to do for my site. If not, that means, I have procrastinated working on the blog, like every other side project that I started earlier.
Why do I ne...]]></description><link>https://blog.vigneshmarimuthu.com/rebuilding-my-personal-blog</link><guid isPermaLink="true">https://blog.vigneshmarimuthu.com/rebuilding-my-personal-blog</guid><category><![CDATA[Blogging]]></category><category><![CDATA[mdx]]></category><category><![CDATA[Next.js]]></category><dc:creator><![CDATA[Vignesh Marimuthu]]></dc:creator><pubDate>Thu, 02 Feb 2023 03:17:42 GMT</pubDate><enclosure url="https://cdn.hashnode.com/res/hashnode/image/stock/unsplash/C3V88BOoRoM/upload/dae70cfde6023d56a384b13ecb206577.jpeg" length="0" type="image/jpeg"/><content:encoded><![CDATA[<p>Visit my blog <a target="_blank" href="https://vigneshmarimuthu.com">here</a>. If you see everything working fine, then I must have done everything that I wanted to do for my site. If not, that means, I have procrastinated working on the blog, like every other side project that I started earlier.</p>
<h3 id="heading-why-do-i-need-a-blog">Why do I need a blog?</h3>
<p>Yes. I do have <strong><em>hashnode</em></strong>. I can write awesome articles with ease and publish everything into a beautifully pre-designed website. Hashnode is making life easier for me. But who likes it when everything comes easy? Definitely not me.<br />I wanted to build something completely to my taste. <mark>The blog should reflect, who I am and what I do before even someone starts reading my "about" section</mark>. I am not just my work. I always wanted to write more about my rants, political opinions, poems, and my 2 cents on random stuff. But I always faced one issue or another with building, structuring, or hosting my blog. So I made some decisions which I really hope work well.</p>
<h3 id="heading-the-decisions">The Decisions</h3>
<ul>
<li><p>For my tech articles related to my work, I am still going to utilize <strong><em>hashnode</em></strong>. It creates less friction and thus it will encourage me to write more.</p>
</li>
<li><p>Previously I was using <strong>React</strong> to build the front-end components. Now I am migrating the code to <strong>NextJS</strong>. More on this, later.</p>
</li>
<li><p>For hosting, I am still going to be using <strong>GitHub pages</strong>. As it offers free hosting and an SSL (I am not a web dev. So I have no idea how this works)</p>
</li>
<li><p>I am someone who never liked to use UI helper packages like <strong><em>bootstrap</em></strong>. I always loved to play with CSS components. I am still this guy. So <strong><em>no no</em></strong> for UI components.</p>
</li>
</ul>
<h3 id="heading-what-about-the-backend">What about the backend?</h3>
<p>This is where this whole rebuilding of the blog gets interesting. I was on the constant lookout for a perfect CMS that will help me with my requirements. The CMS that satisfies my requirement, comes with high pricing. If it is free, it doesn't have the features that I want. I was exploring <strong><em>strapi.js</em></strong> for some time, and it was pretty great as far as I looked into it. But now, that I have <strong><em>hashnode</em></strong> for my tech blog, all I need to worry about is my personal blog which I update rarely. That is when I learned a bit about <strong>MDX</strong></p>
<h3 id="heading-what-is-mdx">What is MDX?</h3>
<p>We all know what Markdown is. Simply put, <em><mark>a text-to-HTML conversion tool.</mark></em> So what is MDX then? MDX lets you embed components directly from your markup. You can add custom view JSX components when rendering your Markdown file. This way, when we fetch a file written in markdown, for each component (heading1, italic, code) we can use individual CSS styling. It provides even more options like passing parameters from the JS component to the MDX for custom .md generation. More on this in later articles.</p>
<h3 id="heading-where-will-be-the-mdx-files-hosted">Where will be the MDX files hosted?</h3>
<p>That is something I am yet to decide. I can easily keep the files in the source code. And every time I wanted to add a new article, all I have to do is, add a new file to a folder and push the changes. But I am afraid, this creates friction and I will get too lazy to write anything. <em>So, please let me know if you know of any platform that lets us host MDX files and also provides an option to edit the file right away online.</em> <strong><em>For free, obviously.</em></strong></p>
<h3 id="heading-is-it-open-source-and-built-in-public">Is it open-source and built-in public?</h3>
<p>Since I am going to use Github pages for hosting, it is obviously going to be open source. But whether or not I am going to build the whole site in public is based on whether or not I have the energy to write everything about what I did. But I assure you, I will write about the problems I faced or about interesting things I learned in the process.</p>
]]></content:encoded></item><item><title><![CDATA[Learn Electron.js with me]]></title><description><![CDATA[The Idea:
I got the idea of building a desktop app that helps the user to organize a folder full of images, based on a pattern like, years, months, or even dates. The idea is, to provide the user an option to select a folder that they want to organiz...]]></description><link>https://blog.vigneshmarimuthu.com/learn-electronjs-with-me</link><guid isPermaLink="true">https://blog.vigneshmarimuthu.com/learn-electronjs-with-me</guid><category><![CDATA[Electron]]></category><category><![CDATA[Build In Public]]></category><dc:creator><![CDATA[Vignesh Marimuthu]]></dc:creator><pubDate>Tue, 31 Jan 2023 02:36:31 GMT</pubDate><enclosure url="https://cdn.hashnode.com/res/hashnode/image/stock/unsplash/jLwVAUtLOAQ/upload/bcfbcbb0ca667bf8cf093c4754df8929.jpeg" length="0" type="image/jpeg"/><content:encoded><![CDATA[<h3 id="heading-the-idea">The Idea:</h3>
<p>I got the idea of building a desktop app that helps the user to organize a folder full of images, based on a pattern like, years, months, or even dates. The idea is, to provide the user an option to select a folder that they want to organize, and also an option to select how they want to organize it. Like, as whether it should be collected in a folder based on year or month, or date.</p>
<h3 id="heading-stuff-we-gonna-use">Stuff we gonna use:</h3>
<p>Initially, I thought of using flutter to build the desktop app. As flutter promises less memory size and takes short time to load the app when compared to electron apps. But later, I realized electron.js has a wide range of developer support and articles to find what I am looking for. Also, I wanted to widen my knowledge in javascript. So I thought it would be better to start with Electron. So the following are the things we gonna use.</p>
<ul>
<li><p>React app with create-react-app</p>
</li>
<li><p>Install electron framework into it</p>
</li>
<li><p>Find a way to access the terminal command to implement our requirement</p>
</li>
</ul>
<h3 id="heading-info-about-me-no-one-asked-for">Info about me, no one asked for</h3>
<p>I am an Android developer, who predominantly codes in Kotlin and the native android framework. But occasionally I love to explore other frameworks of different domains. Web development is something I recently started exploring, and it is fun so far. I even managed to create a personal portfolio/blog/a place to brag about myself kinda thing with ReactJS. You can find it <a target="_blank" href="http://vigneshmarimuthu.com">here</a>.</p>
<h3 id="heading-when-are-we-gonna-start">When are we gonna start</h3>
<p>If you are interested stay pretty close to this space. I have already created a base structure including the react app and electron framework added ready to go. Once it is done, I'll share the repository so that you can clone it and tag along.</p>
]]></content:encoded></item></channel></rss>