<?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 Kishan Maurya on Medium]]></title>
        <description><![CDATA[Stories by Kishan Maurya on Medium]]></description>
        <link>https://medium.com/@kishankrmaurya?source=rss-d4d9f7a8246b------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*uJfrSG31IkHCcahbTP8n3Q.png</url>
            <title>Stories by Kishan Maurya on Medium</title>
            <link>https://medium.com/@kishankrmaurya?source=rss-d4d9f7a8246b------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Tue, 17 Nov 2026 17:08:26 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@kishankrmaurya/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[Your Android SDK Just Crashed in Someone Else’s App. Now What?]]></title>
            <link>https://proandroiddev.com/your-android-sdk-just-crashed-in-someone-elses-app-now-what-3586fc9f84af?source=rss-d4d9f7a8246b------2</link>
            <guid isPermaLink="false">https://medium.com/p/3586fc9f84af</guid>
            <category><![CDATA[crashlytics]]></category>
            <category><![CDATA[android-sdk]]></category>
            <category><![CDATA[crash]]></category>
            <category><![CDATA[sdk]]></category>
            <category><![CDATA[android-development]]></category>
            <dc:creator><![CDATA[Kishan Maurya]]></dc:creator>
            <pubDate>Thu, 02 Jul 2026 12:07:54 GMT</pubDate>
            <atom:updated>2026-07-02T18:41:27.990Z</atom:updated>
            <content:encoded><![CDATA[<p><em>How to report your own SDK’s crashes without stepping on the host app’s Crashlytics — and the gotchas nobody warns you about.</em></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/934/1*Wd1ahYYVyDskvCpDLHmMmw.png" /></figure><p>Here’s a situation every SDK developer eventually hits.<br>You ship an Android library. It runs inside apps you don’t own, written by teams you’ll never meet. One day a bug in your code throws an uncaught exception on a user’s phone. The app dies. And you… have no idea it happened.<br>You want crash reports for <em>your code</em>. The obvious move is to install a crash handler:</p><pre>Thread.setDefaultUncaughtExceptionHandler(myHandler)</pre><p>Do that and you’ve just broken the host app.<br>Let me explain why, because the reason is the whole story.</p><h4>Android gives you exactly one slot</h4><blockquote>Thread.setDefaultUncaughtExceptionHandler is a single global setter. One slot. Whoever calls it last wins, and everyone before them is silently evicted.</blockquote><p>The host app almost certainly got there first. They’re running Firebase <strong>Crashlytics</strong>, or <strong>Sentry</strong>, or <strong>Bugsnag</strong> — and every one of those works by owning that slot. When you call <strong>setDefaultUncaughtExceptionHandler</strong> from your SDK, you don’t add a handler. You replace theirs. Their crash reporting goes dark, and they won’t find out until an incident review turns up a suspiciously quiet dashboard.</p><p>So the naive approach is off the table. You can’t own the slot. But you still need your crashes.</p><h4>The decorator: don’t take the slot, wrap it</h4><blockquote>The trick is to stop thinking of the handler as something you own and start thinking of it as something you decorate.</blockquote><p>When your SDK initializes, read whatever handler is already installed. Then install your own — one that inspects each crash, keeps the ones that belong to you, and always forwards the exception to the handler you found. The host’s Crashlytics still fires. You just got a look on the way through.</p><pre>crash → [your interceptor] → host&#39;s handler (Crashlytics/Sentry/…) → system default<br>              │<br>              └─ if the crash is yours: capture it, then delegate anyway</pre><p>That single rule —<em> always delegate downstream</em> — is what makes this safe to embed. You are a guest. You look, you don’t touch. The host’s reporter sees 100% of crashes exactly like it did before you showed up.</p><p>This is the idea behind <strong>crashsink</strong>, a tiny library I built for exactly this problem. The rest of this post is the stuff I learned making it actually work in the wild, because the decorator idea is the easy 20%.</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fcodepen.io%2FKishan-Kumar-Maurya%2Fembed%2Fpreview%2FQwdOGJM%3Fdefault-tabs%3Dcss%252Cresult%26height%3D600%26host%3Dhttps%253A%252F%252Fcodepen.io%26slug-hash%3DQwdOGJM&amp;display_name=CodePen&amp;url=https%3A%2F%2Fcodepen.io%2FKishan-Kumar-Maurya%2Fpen%2FQwdOGJM&amp;image=https%3A%2F%2Fshots.codepen.io%2Fusername%2Fpen%2FQwdOGJM-512.jpg%3Fversion%3D1782993536&amp;type=text%2Fhtml&amp;schema=codepen" width="800" height="600" frameborder="0" scrolling="no"><a href="https://medium.com/media/452eaaa0df0241e9b709d47e00203fdd/href">https://medium.com/media/452eaaa0df0241e9b709d47e00203fdd/href</a></iframe><h4>“Is this crash mine?” is harder than it looks</h4><blockquote>You only want to capture crashes caused by your code. A crash bubbling up from the host, or from some other SDK, isn’t yours to report — you’d just be spamming your own backend with noise you can’t act on.</blockquote><p>The naive check — “<strong>does the top stack frame live in my package?</strong>” — is wrong in a subtle way. Exceptions get wrapped. A <strong>RuntimeException</strong> caused by an <strong>IOException</strong> caused by the actual bug: the top frame is often framework code, not the culprit. And the top of the stack is frequently <strong>java.*</strong> or<strong> android.*</strong> plumbing regardless. So attribution walks the chain properly:</p><pre>1.Follow getCause() down to the deepest cause (bounded, so a malicious cyclic cause chain can&#39;t hang you).<br>2.Skip framework frames - java., kotlin., android., and friends.<br>3.Look at the first application frame that&#39;s left. Does its class name start with your configured package prefix?</pre><p>If yes, it’s yours. If no, hands off.</p><p>There’s a nice edge case this gets right. Say the host registers a <em>callback</em> with your SDK, you invoke it, and <em>their callback throws</em>. The crash passes <em>through</em> your code, but the culprit frame belongs to the host. The starts-with check leaves it to them — which is correct. <br>A crash routing through you isn’t a crash caused by you.</p><pre>CrashReporter.create(<br>    context,<br>    sink = { token, exceptionValues, level, culprit, timestamp, contexts -&gt;<br>        // ship it to your backend<br>    },<br>    ownedPrefix = &quot;com.mycompany.mysdk.&quot;<br>)</pre><p>One string, ownedPrefix, decides what you own.</p><h4>The dying-thread problem</h4><blockquote>Now the part that separates a toy from something you’d actually embed in a payment SDK, an analytics SDK, a chat SDK, a maps SDK, an ads SDK, or any other kind of mobile SDK.</blockquote><p>When uncaughtException fires, you are running on a thread that is <em>about to die</em>. The process is in an undefined state. Whatever you do here, you do under the worst conditions your code will ever see:</p><p>• <strong>You can’t throw</strong>. An exception in a crash handler is the definition of adding insult to injury — and it can swallow the original crash entirely.</p><p>• <strong>You can’t block forever</strong>. Hang here and you turn a clean crash into an ANR, which is a <em>worse</em> user experience than the crash you were trying to report.</p><p>• <strong>You shouldn’t allocate</strong>. The heap may be exhausted (<em>plenty of crashes are OOMs</em>). Allocating in the handler can fail or make things worse.</p><p>So <strong>crashsink</strong> does almost nothing on the dying thread. It hands the actual work — building the crash payload, redacting it, writing it to disk — to a dedicated daemon thread, and the dying thread just waits on a latch with a hard timeout. Then, no matter what happened, it delegates downstream in a <strong><em>finally</em></strong> block. The whole body is wrapped in <strong><em>catch (Throwable)</em></strong>. Nothing the interceptor does can prevent the host’s handler from running.</p><p>The other half of that design: <strong>you don’t send the crash at crash time</strong>. Network calls from a dying process are a fantasy. Instead it’s two phases:</p><p>• <strong>At crash time</strong>: write a small, redacted file to disk. Fast, bounded, local.<br>• <strong>On the next app launch</strong>: read those files, hand each to your sink to upload, delete on success, <em>keep-and-retry</em> on failure.</p><p>Write now, deliver later. It’s the only pattern that survives a process that’s actively falling over.</p><h4>The gotchas I only found by shipping</h4><blockquote>The core pipeline is maybe half the work. The other half is the stuff that bites you in production.</blockquote><p><strong>Double initialization stacks interceptors</strong>. A host might call your <strong><em>SDK’s init()</em></strong> from more than one place — Application, then an Activity, then a deep link handler. Naively, each call wraps the chain again, and now a single crash gets captured and delivered <em>twice</em>. The fix: before installing, walk the existing chain looking for an interceptor that already owns your prefix. Found one? Adopt it, don’t stack. Install-once has to be an invariant, not a hope.</p><p><strong>Two SDKs, one process, one directory.</strong> If two different SDKs both embed crashsink in the same app, and both write crash files to the same folder, they’ll trample each other. The fix is to namespace the crash directory per package prefix —<strong><em> filesDir/crashsink/&lt;your-prefix&gt;/ </em></strong>— so two guests (or a guest and the host) never collide.</p><p><strong>Obfuscation silently breaks attribution</strong>. This one’s nasty because it fails quietly. Attribution matches on package names. If a consumer runs R8/ProGuard and obfuscates your package, <strong><em>com.mycompany.mysdk.Worker</em></strong> becomes <strong><em>a.b.c</em></strong> at runtime, your prefix stops matching, and crashes are silently not captured. No error. Just… nothing. The mitigation ships inside the AAR: a <strong><em>consumer-rules.pro</em></strong> with <strong><em>-keeppackagenames and -keepattributes SourceFile,LineNumberTable</em></strong>, so the rules travel with the artifact and apply to the consumer’s R8 run automatically.</p><p><strong>Keep the public API tiny</strong>. Everything that isn’t the consumer’s contract is <strong><em>internal</em></strong>. The entire public surface is one factory method and one interface (<strong><em>CrashSink</em></strong>, a SAM you implement as a lambda). Small surface means you can refactor the guts without breaking anyone, and there’s less for a consumer to misuse.</p><h4>Installing it</h4><blockquote>crashsink is on JitPack, which builds straight from a Git tag — no publish step, no auth needed for public repos.</blockquote><pre>// settings.gradle.kts<br>dependencyResolutionManagement {<br>    repositories {<br>        google()<br>        mavenCentral()<br>        maven { url = uri(&quot;https://jitpack.io&quot;) }<br>    }<br>}<br><br>// build.gradle.kts<br>dependencies {<br>    implementation(&quot;com.github.droiddevgeeks:crash-interceptor:0.1.0&quot;)<br>}</pre><p>Then wire it up from your SDK’s own init entry point — <em>not</em> from an Application class, because as a guest SDK you don’t own one:</p><pre>object MySdk {<br>    private var reporter: CrashReporter? = null<br><br>    @Synchronized<br>    fun init(context: Context) {<br>        if (reporter != null) return  // idempotent — double-init is safe<br>        reporter = CrashReporter.create(<br>            context.applicationContext,<br>            { _, exceptionValues, _, culprit, timestamp, contexts -&gt;<br>                // POST to your backend here<br>            },<br>            ownedPrefix = &quot;com.mycompany.mysdk.&quot;<br>        ).apply {<br>            install()                 // also flushes crashes from the previous run<br>            startCapturing(&quot;session-id&quot;)<br>        }<br>    }<br>}</pre><p>That’s it. Your crashes go to you; everything else — including your crashes, re-thrown — goes to the host’s reporter.</p><h4>Wrapping up</h4><p>Crash reporting for a guest SDK is a constraint problem more than a code problem. Android hands out one crash-handler slot, the host already owns it, and your job is to observe without disturbing. Decorate the slot, always delegate, attribute carefully, and do the dangerous work off the dying thread.</p><p><strong><em>crashsink</em></strong> is open source — <a href="http://github.com/droiddevgeeks/crash-interceptor"><strong>github.com/droiddevgeeks/crash-interceptor</strong></a><strong>.</strong> It’s small enough to read in one sitting, which is kind of the point. If you’re shipping an SDK and flying blind on your own crashes, give it a look.</p><p><a href="https://droiddevgeeks.github.io/crash-interceptor/">crashsink - decorate the crash handler, always delegate</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=3586fc9f84af" width="1" height="1" alt=""><hr><p><a href="https://proandroiddev.com/your-android-sdk-just-crashed-in-someone-elses-app-now-what-3586fc9f84af">Your Android SDK Just Crashed in Someone Else’s App. Now What?</a> was originally published in <a href="https://proandroiddev.com/">ProAndroidDev</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Git Bisect: Stop Reading Diffs, Start Searching History]]></title>
            <link>https://proandroiddev.com/git-bisect-stop-reading-diffs-start-searching-history-8805d8f0e469?source=rss-d4d9f7a8246b------2</link>
            <guid isPermaLink="false">https://medium.com/p/8805d8f0e469</guid>
            <category><![CDATA[github]]></category>
            <category><![CDATA[development-commits]]></category>
            <category><![CDATA[git-bisect]]></category>
            <category><![CDATA[git]]></category>
            <category><![CDATA[git-commit]]></category>
            <dc:creator><![CDATA[Kishan Maurya]]></dc:creator>
            <pubDate>Mon, 22 Jun 2026 09:55:01 GMT</pubDate>
            <atom:updated>2026-06-26T21:02:37.802Z</atom:updated>
            <content:encoded><![CDATA[<blockquote>It worked Tuesday. It’s broken Friday. Somewhere in the 300 commits in between, someone broke it — and now it’s your job to find out who, what, and where.. Here’s how git bisect finds the exact one in a handful of check</blockquote><p>Most developers reach for git blame here. Some scroll through the commit log squinting at messages. A brave few git checkout random commits and poke at the app until something gives. All three are slower than they need to be, and two of them will lie to you.</p><p>There’s a better tool for this exact shape of problem: git bisect. Let&#39;s break down what it does, how the test loop actually works, and when it beats your IDE.</p><h3>The problem bisect actually solves</h3><p>You have a regression. You know a commit where things worked (call it <strong>good</strong>) and a commit where they don’t (call it <strong>bad</strong>, usually HEAD). The breaking change is one of the commits in between. The question is: <em>which one?</em></p><p>The naive approach is a linear scan — check commits one by one until you hit the culprit. With 300 commits, that’s up to 300 checks.</p><p>git bisect does a <strong>binary search</strong> instead. It checks out the commit halfway between good and bad, you test it, and based on your verdict it throws away half the remaining range. Repeat.</p><ul><li>300 commits → ~9 checks (log₂300 ≈ 8.2)</li><li>10,000 commits → ~14 checks</li></ul><p>That’s the entire value proposition: it turns “which of N commits broke this” from a linear problem into a logarithmic one.</p><p>The one assumption it relies on: the bug is <strong>monotonic</strong>. Once introduced, it stays broken through to HEAD. If a bug appears, gets accidentally masked, then reappears, plain bisect can point you at the wrong commit. Keep that in your back pocket — it&#39;s the silent failure mode.</p><h3>The mental model</h3><p>Two markers, one search:</p><ul><li><strong>good</strong> — a commit where the behavior was correct.</li><li><strong>bad</strong> — a commit where it’s broken.</li></ul><p>Git keeps halving the range between them, asking you “good or bad?” at each midpoint, until only one commit remains — the <strong>first bad commit</strong>. That’s the one that introduced the regression.</p><p>You’re not reading code. You’re answering a yes/no question about behavior, repeatedly. Git does the bookkeeping.</p><h3>The commands</h3><pre># Start a session<br>git bisect start<br><br># Mark the current (broken) state<br>git bisect bad                 # or: git bisect bad &lt;commit&gt;<br><br># Mark a commit you know was fine<br>git bisect good v1.2.0         # a tag, SHA, or HEAD~50<br><br># --- git checks out a commit in the middle ---<br># Test it. Then give the verdict:<br>git bisect good                # this one works<br>git bisect bad                 # this one is broken<br>git bisect skip                # can&#39;t test this one (won&#39;t build, etc.)<br><br># Repeat until git prints:<br>#   &lt;sha&gt; is the first bad commit<br><br># Return to where you started:<br>git bisect reset</pre><p>Shortcut to start with both markers at once:</p><pre>git bisect start &lt;bad&gt; &lt;good&gt;      # e.g. git bisect start HEAD v1.2.0</pre><h3>Wait — how do I actually test each commit?</h3><p>This is the part that trips everyone up the first time, so let’s be concrete and use a real repo you can clone and follow along with: <a href="https://github.com/droiddevgeeks/git-bisect-demo"><strong>droiddevgeeks/git-bisect-demo</strong></a>. The key idea to hold onto: <strong>git moves your working files for you, and you test whatever it leaves you sitting on.</strong></p><p>That repo is a tiny semver-based library, released as version-check. It worked at release 1.0.0 (commit 498b52c) and it&#39;s broken at HEAD. Somewhere in the 15 commits between them, a commit titled &quot;refactor: simplify isUpgrade comparison&quot; quietly swapped two arguments:</p><pre>// before — correct<br>function isUpgrade(from, to) {<br>  return semver.gt(to, from);<br>}<br><br>// after - looks like a harmless cleanup, but the args are flipped<br>function isUpgrade(from, to) {<br>  return semver.gt(from, to);<br>}</pre><p>Nothing about that line <em>looks</em> wrong, which is exactly why blame wouldn’t help you. The visible symptom: isUpgrade(&#39;1.0.0&#39;, &#39;2.0.0&#39;) returns false when it should be true. So clone it and set up the two markers:</p><pre>git clone https://github.com/droiddevgeeks/git-bisect-demo.git<br>cd git-bisect-demo &amp;&amp; npm install<br><br>git bisect start<br>git bisect bad              # HEAD is broken<br>git bisect good 498b52c     # the release where it still worked</pre><p>The moment you’ve given git one good and one bad, it doesn&#39;t wait. It checks out a commit in the middle of that range — the actual files on your disk change to what they looked like at that commit:</p><pre>Bisecting: 6 revisions left to test after this (roughly 3 steps)<br>[eb018fe] refactor: simplify isUpgrade comparison</pre><p>Right now, <strong>your code is at commit </strong><strong>eb018fe</strong> — your editor, your files, everything is that version. That&#39;s the commit git wants you to test.</p><h3>There’s no magic. You just run your thing.</h3><p>git has no idea what “working” means for your project. <em>You</em> decide that. In this repo, “working” means isUpgrade(&#39;1.0.0&#39;, &#39;2.0.0&#39;) comes back true, so the test is a one-line probe:</p><pre>node -e &quot;const {isUpgrade}=require(&#39;./src/upgrade&#39;); console.log(isUpgrade(&#39;1.0.0&#39;,&#39;2.0.0&#39;))&quot;</pre><p>Your own project might need something else, but it’s always the same move — reproduce the bug and look:</p><ul><li><strong>A web app?</strong> Start the server, click the broken button, see if it misbehaves.</li><li><strong>A library function?</strong> Call it with the input that breaks and check the output — exactly the probe above.</li><li><strong>A test suite?</strong> Run the test that catches it: npm test or pytest tests/test_x.py.</li><li><strong>A build error?</strong> Run make / npm run build and see if it fails.</li></ul><p>Look at the result with your own eyes and decide: is the bug here or not?</p><h3>Then tell git the verdict</h3><p>On eb018fe, the probe prints false — broken — so we mark it bad:</p><pre>git bisect good    # bug is NOT here, this commit is fine<br>git bisect bad     # bug IS here, this commit is broken   &lt;- our case</pre><p>As soon as you answer, git jumps to the next midpoint and checks out a different commit. Your files change again. You test again. You answer again.</p><pre>Bisecting: 2 revisions left to test after this (roughly 2 steps)<br>[20d1744] docs: add usage section to README</pre><p>That’s the entire loop: <strong>git checks out a commit → you test it → you say good or bad → git checks out the next one.</strong> Each answer halves what’s left, which is why the “revisions left” number keeps dropping fast.</p><h3>The full session, start to finish</h3><p>Here’s the whole thing in one block — the real transcript, testing that one expression at each step git parks you on:</p><pre>$ git bisect start<br>status: waiting for both good and bad commits<br>$ git bisect bad                  # HEAD is broken<br>status: waiting for good commit(s), bad commit known<br>$ git bisect good 498b52c         # the release where it worked<br>Bisecting: 6 revisions left to test after this (roughly 3 steps)<br>[eb018fe] refactor: simplify isUpgrade comparison<br><br># git parked me on eb018fe. Test it my way:<br>$ node -e &quot;const {isUpgrade}=require(&#39;./src/upgrade&#39;); console.log(isUpgrade(&#39;1.0.0&#39;,&#39;2.0.0&#39;))&quot;<br>false                             # broken - bug is here<br>$ git bisect bad<br>Bisecting: 2 revisions left to test after this (roughly 2 steps)<br>[20d1744] docs: add usage section to README<br>$ node -e &quot;const {isUpgrade}=require(&#39;./src/upgrade&#39;); console.log(isUpgrade(&#39;1.0.0&#39;,&#39;2.0.0&#39;))&quot;<br>true                              # fine here<br>$ git bisect good<br>Bisecting: 0 revisions left to test after this (roughly 1 step)<br>[efb8d44] refactor: extract compare() helper<br>$ node -e &quot;const {isUpgrade}=require(&#39;./src/upgrade&#39;); console.log(isUpgrade(&#39;1.0.0&#39;,&#39;2.0.0&#39;))&quot;<br>true                              # fine here too<br>$ git bisect good</pre><p>Three tests in, git names the culprit:</p><pre>eb018fe is the first bad commit<br>    refactor: simplify isUpgrade comparison<br> src/upgrade.js | 2 +-<br> 1 file changed, 1 insertion(+), 1 deletion(-)</pre><p>That’s the whole point in miniature: out of a dozen commits in range, you ran the test three times — not twelve — and landed on the exact commit that flipped the behavior, down to the one-line change.</p><h3>Don’t forget to reset</h3><p>While bisecting, your code is bouncing around old commits. When you’re done, put your files back:</p><pre>git bisect reset</pre><p>This returns you to where you were before you started (usually the tip of your branch). Forget this step and you’ll be staring at old code wondering why your changes vanished.</p><p>So the short answer to “how do I test?” — you test exactly the way you always would. git’s only job is to keep moving you to the right commit to check. Your job at each step is just: run the thing, look, and say good or bad.</p><h3>Blame vs Bisect — the debate worth having</h3><p>Here’s the objection almost every developer raises, and it’s a good one:</p><blockquote><em>“My IDE shows </em><em>git blame inline. I know which flow is broken, so I&#39;ll just open that file and check the commit history directly. Why would I ever run bisect?&quot;</em></blockquote><p>For a lot of bugs, that’s exactly right. If the broken behavior lives in export.js and the bug is <em>visible in the code</em>, open the file, blame the suspicious lines, done. Bisect would be overkill.</p><p>But “I know which flow is broken” is carrying the entire argument — and it only holds for the easy bugs. The expensive ones are precisely where blame falls apart.</p><h3>Where git blame quietly fails</h3><p><strong>1. The bug isn’t in the file you’d blame.</strong><br>The export flow breaks, but the real cause is a commit that changed a shared utility, a config default, a dependency version, or a serializer three layers down. You can’t blame the right file because the broken <em>behavior</em> and the broken <em>code</em> aren’t in the same place. Blame only works once you’ve already guessed the location correctly. Bisect <em>finds</em> the location for you.</p><p><strong>2. The break has no line to blame.</strong></p><ul><li>A dependency bump (package.json says ^1.2.0; the broken code is inside node_modules).</li><li>A merge commit that combined two individually-fine branches into a broken whole.</li><li>A config, environment, or data-migration change.</li></ul><p>git blame points at a line of source. None of these are a line of source. Bisect tests <em>behavior</em>, so it catches all of them.</p><p><strong>3. Blame tells you “who last touched this line,” not “what broke it.”</strong><br>Say the failing line is const result = transform(data). Blame says it was last edited 8 months ago in a formatting commit. Useless — the line didn&#39;t change; the behavior of transform did, somewhere else entirely. Blame chases the wrong scent whenever the cause is non-local.</p><p><strong>4. The refactor problem.</strong><br>Someone reformatted the file, moved it, or ran a linter across the repo. Now blame attributes half the file to that mechanical commit, and you’re stuck running git blame -w -C gymnastics to see through it. Bisect is immune — it never reads the file&#39;s line history at all.</p><h3>The real distinction</h3><ul><li><strong>Blame answers a <em>spatial</em> question:</strong> “who wrote this specific line?” You need to already know the line.</li><li><strong>Bisect answers a <em>temporal</em> question:</strong> “which commit changed the program’s behavior?” You need to know how to reproduce the bug, nothing more.</li></ul><p>Put simply: <strong>blame is a lookup, bisect is a search.</strong> Reach for blame when you know <em>where</em>. Reach for bisect when you only know <em>when</em>.</p><h3>The honest scorecard</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/743/1*LpqkoAcogCgfzw5CwuG8dg.png" /></figure><h3>Full command reference</h3><pre>git bisect start                         //Begin a session<br>git bisect bad [&lt;commit&gt;]                //Mark a commit broken (default HEAD)<br>git bisect good [&lt;commit&gt;]               //Mark a commit working<br>git bisect skip [&lt;commit&gt;]               //Can&#39;t test this one — exclude it<br>git bisect reset [&lt;commit&gt;]              //End session, return to original HEAD<br>git bisect log                           //Print the decisions so far<br>git bisect replay &lt;file&gt;                 //Re-run a saved session from a log<br>git bisect visualize / view              //Open gitk / log of the remaining range<br>git bisect terms                         //Rename good/bad (e.g. old/new)</pre><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=8805d8f0e469" width="1" height="1" alt=""><hr><p><a href="https://proandroiddev.com/git-bisect-stop-reading-diffs-start-searching-history-8805d8f0e469">Git Bisect: Stop Reading Diffs, Start Searching History</a> was originally published in <a href="https://proandroiddev.com/">ProAndroidDev</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Handle LiveData Observer properly in ViewModel Testing]]></title>
            <link>https://kishankrmaurya.medium.com/handle-livedata-observer-properly-in-viewmodel-testing-8f88d04f87f8?source=rss-d4d9f7a8246b------2</link>
            <guid isPermaLink="false">https://medium.com/p/8f88d04f87f8</guid>
            <category><![CDATA[junit]]></category>
            <category><![CDATA[testing]]></category>
            <category><![CDATA[livedata-testing]]></category>
            <category><![CDATA[viewmodel-testing]]></category>
            <category><![CDATA[mvvm]]></category>
            <dc:creator><![CDATA[Kishan Maurya]]></dc:creator>
            <pubDate>Tue, 08 Jun 2021 11:41:54 GMT</pubDate>
            <atom:updated>2021-06-08T11:41:54.886Z</atom:updated>
            <content:encoded><![CDATA[<p>In MVVM, ViewModel exposes streams of events to which the Views can bind. Generally, we use LiveData inside ViewModel and the view can observe for live data changes.</p><p>When it comes to unit testing for ViewModel, we create an observer, passes that observer to Live data, and verify its changed event.</p><pre>viewModel.sessionSubmitLiveData.observeForever(<em>dataObserver</em>)<br>viewModel.submitSession(submitRequest)<br><em>verify(dataObserver).onChanged(data)</em></pre><p>You can explore this approach in the below article.</p><p><a href="https://medium.com/mindorks/unit-testing-for-viewmodel-19f4d76b20d4">Unit Testing for ViewModel</a></p><h4>If we want to assert data, then how can we do that?</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*IMee1WMCKmqfLZCg" /><figcaption>Photo by <a href="https://unsplash.com/@brucemars?utm_source=medium&amp;utm_medium=referral">bruce mars</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><p>Let take an example, we make a simple API call, we show loading, then hide loading based on API event, then show data/error. So we have 3 states to represent. Thanks to Kotlin, we have <a href="https://kotlinlang.org/docs/sealed-classes.html">sealed</a> class</p><h4>Loading, Error, Success</h4><pre>sealed class DataState&lt;out T&gt; {<br>    data class Loading(val isLoading: Boolean) : DataState&lt;Nothing()<br>    data class Error(val error: Throwable) : DataState&lt;Nothing&gt;()<br>    data class Success&lt;T&gt;(val data: T) : DataState&lt;T&gt;()<br>}</pre><p>This is a simple ViewModel class that makes 1 API call, gets data from the server then updates live data. As soon as we trigger API call, we show loading, then we hide loading then we show data/error based on API status.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/4a6ea7b5f8226e891c9504e653ea6c1f/href">https://medium.com/media/4a6ea7b5f8226e891c9504e653ea6c1f/href</a></iframe><h4>How to test the above scenario?</h4><p>Create a mock observer &amp; <a href="https://site.mockito.org/javadoc/current/org/mockito/ArgumentCaptor.html">argumentCaptor</a> with the same type as we used for LiveData in ViewModel.</p><blockquote>ArgumentCaptor is used to capture argument values for further assertions.</blockquote><pre>val argCaptor = <em>argumentCaptor</em>&lt;DataState&lt;SubmitResponse&gt;&gt;()</pre><pre>private val submitStateObserver by <em>lazy </em><strong>{</strong><em>mock</em>&lt;Observer&lt;DataState&lt;SubmitResponse&gt;&gt;&gt;() <strong>}</strong></pre><p>Pass this argumentCaptor to the observer to capture all value changes for live data. This will give all events values.</p><pre>onChanged(argCaptor.capture())</pre><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/8fbd627097989bb156700a4c398855d4/href">https://medium.com/media/8fbd627097989bb156700a4c398855d4/href</a></iframe><p>Source Code :</p><p><a href="https://github.com/droiddevgeeks/LibSysManagement">droiddevgeeks/LibSysManagement</a></p><p>Thanks for reading the article.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/378/1*nIieoCW88pMMe1OhyWxqUw.png" /></figure><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=8f88d04f87f8" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Unit testing using Spek framework]]></title>
            <link>https://proandroiddev.com/unit-testing-using-spek-framework-af27ae12c26e?source=rss-d4d9f7a8246b------2</link>
            <guid isPermaLink="false">https://medium.com/p/af27ae12c26e</guid>
            <category><![CDATA[android]]></category>
            <category><![CDATA[unit-test-framework]]></category>
            <category><![CDATA[spek]]></category>
            <category><![CDATA[kotlin]]></category>
            <category><![CDATA[viewmodel-testing]]></category>
            <dc:creator><![CDATA[Kishan Maurya]]></dc:creator>
            <pubDate>Thu, 16 Jul 2020 19:06:59 GMT</pubDate>
            <atom:updated>2020-07-16T19:06:59.075Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/809/1*cnfupMo1VxVFhEVYsj3xMA.png" /></figure><p>In my <a href="https://medium.com/mindorks/unit-testing-for-viewmodel-19f4d76b20d4">previous</a> articles on unit testing, I have talked about ViewModel, Usecase, Repository testing using JUnit &amp; Mockito. Today I am going to explore about Spek framework for unit testing.</p><h4>What is Spek?</h4><p>Spek is a <strong>Kotlin-based Specification Testing framework</strong>. Spek is written in Kotlin and specifications or tests we write will be in Kotlin. However, our SUT (System Under Test) can be Java or Kotlin.</p><p>Currently, Spek is implemented as a JUnit Platform <strong>TestEngine</strong>. This means that we can easily plug it into any project that already uses JUnit 5.</p><blockquote>This allows us to easily define specifications in a clear, understandable, human-readable way. This framework allows you to describe tests and expected behaviors in a more readable way.</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*J2LyWSyoejH1l9Z6AHoHbw.png" /></figure><h4>How to start within the Android project?</h4><ol><li>Add following dependencies in Build.gradle( Project level)</li></ol><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/0b9e4069aaf7a36470d1003f4cc9cb32/href">https://medium.com/media/0b9e4069aaf7a36470d1003f4cc9cb32/href</a></iframe><p>2. Add the following dependencies in Build.gradle( App level)</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/18f1c23755d7d9f06dcbb83ed2cf58a6/href">https://medium.com/media/18f1c23755d7d9f06dcbb83ed2cf58a6/href</a></iframe><p>org.jetbrains.spek:spek-api is needed during compilation<br>org.jetbrains.spek:spek-junit-platform-engine is needed during runtime.</p><p>For writing the test cases, we need to choose which DSL style to use.<br>Spek offers two styles of DSL for writing test cases, namely <a href="https://www.spekframework.org/specification/">Specification</a> (describe -&gt; context -&gt; it) and <a href="https://www.spekframework.org/gherkin/">Gherkin</a>(Feature-&gt;Scenario-&gt;When-&gt;then )</p><p>We will use the Specification DSL.</p><blockquote>{describe -&gt; it}</blockquote><p>The style follows the <strong>Jasmine</strong> and <strong>Mocha</strong> style frameworks, where things are defined in describe blocks.</p><blockquote><strong><em>describe</em></strong><em>: which defines the context of what we’re testing. We can nest as many </em><em>describes as we want.<br></em><strong><em>it</em></strong><em>: which defines the actual tests i.e what to be verified once the action is executed.</em></blockquote><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/7000b2b4894c356f85ee14cd97bcc5dc/href">https://medium.com/media/7000b2b4894c356f85ee14cd97bcc5dc/href</a></iframe><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*YIGOHvGcCR60L4kaKoevEw.png" /><figcaption>Output</figcaption></figure><p>Spek doesn’t have any built-in assertions. It allows us to use whatever assertion framework we’re most comfortable with eg. <a href="https://github.com/MarkusAmshove/Kluent">Kluent</a>, <a href="https://github.com/winterbe/expekt">Expekt</a>, or <a href="https://github.com/npryce/hamkrest">HamKrest</a>.</p><h3>Working with Spek</h3><p>Tests are written using nested lambdas, each level can either be a group or a test.</p><blockquote><strong><em>Test</em></strong><em> is where we place our assertions/checks.<br></em><strong><em>Group</em></strong><em> is used to organize your tests. It can contain test and other group as well</em></blockquote><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/2770579945d07c1b41f91c35c720b977/href">https://medium.com/media/2770579945d07c1b41f91c35c720b977/href</a></iframe><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*VPLsnwsODwtQ9YG1T-IqNA.png" /></figure><h3>Fixtures</h3><p>Spek allows running arbitrary code before and after a group and test is executed. <strong>Spek can also execute logic before/after tests.</strong></p><blockquote><em>beforeGroup, afterGroup<br>beforeEachTest, afterEachTest</em></blockquote><p>Spek will execute each <strong>beforeGroup</strong><em> </em>block immediately before every group and each <strong>afterGroup</strong> block immediately after every group in the current nesting.</p><p>Spek will execute each <strong>beforeEachTest</strong> block immediately before every <em>it </em>block and each <strong>afterEachTest</strong> block immediately after every<em> it</em> block.</p><pre>afterGroup <strong>{<br>    </strong>clearInvocations(endpoint)<br><strong>}</strong></pre><pre>beforeEachTest <strong>{<br>    </strong>endpoint = <em>mock</em>()<br><strong>}<br><br></strong>afterEachTest <strong>{<br>    </strong>reset(endpoint)<br><strong>}</strong></pre><h4><strong>Ignoring some Test cases :</strong></h4><p>we can ignore a test with a prefix of “x” like this. (e.g. xdescribe, xit )</p><pre><em>xit</em>(&quot;Should return list of comments&quot;) <strong>{}</strong></pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*aJ38B8WPsijBOrudSzcV4w.png" /></figure><h3>Issues Observed :</h3><ol><li>When we try to use test rule with Rule annotation, we get the following error.<br><strong>This annotation is not applicable to target ‘local variable’</strong></li></ol><pre>@Rule<br>var rule: TestRule = InstantTaskExecutorRule()</pre><h4>Solution :</h4><p><a href="https://github.com/spekframework/spek/issues/337">https://github.com/spekframework/spek/issues/337</a></p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/aaf2fc3cc355cfee2d94c6858b4c62a4/href">https://medium.com/media/aaf2fc3cc355cfee2d94c6858b4c62a4/href</a></iframe><p>You can find the complete test using Spek on <a href="https://github.com/droiddevgeeks/GithubFirebaseIssue/commit/78fa6be035400b28c1aa4a6ffdd8638979ed3c6f">this</a> commit.</p><p><a href="https://github.com/droiddevgeeks/GithubFirebaseIssue">droiddevgeeks/GithubFirebaseIssue</a></p><p>References : <br><a href="https://www.spekframework.org/core-concepts/">https://www.spekframework.org/core-concepts/</a><br><a href="https://spekframework.github.io/spek/docs/latest/#_what_is_spek">https://spekframework.github.io/spek/docs/latest/#_what_is_spek</a></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/378/1*c-Wz8dcjnMbYVw-00EsRLg.png" /></figure><p>Thanks for reading the article. You could check out my other interesting topics <a href="https://medium.com/@kishankr.maurya">here</a>.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=af27ae12c26e" width="1" height="1" alt=""><hr><p><a href="https://proandroiddev.com/unit-testing-using-spek-framework-af27ae12c26e">Unit testing using Spek framework</a> was originally published in <a href="https://proandroiddev.com/">ProAndroidDev</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Control Over Google map marker]]></title>
            <link>https://kishankrmaurya.medium.com/control-over-google-map-marker-742dc6035a43?source=rss-d4d9f7a8246b------2</link>
            <guid isPermaLink="false">https://medium.com/p/742dc6035a43</guid>
            <category><![CDATA[kotlin]]></category>
            <category><![CDATA[marker]]></category>
            <category><![CDATA[google-map-api]]></category>
            <category><![CDATA[maps]]></category>
            <category><![CDATA[custom-marker]]></category>
            <dc:creator><![CDATA[Kishan Maurya]]></dc:creator>
            <pubDate>Wed, 17 Jun 2020 03:27:56 GMT</pubDate>
            <atom:updated>2020-06-17T03:27:56.522Z</atom:updated>
            <content:encoded><![CDATA[<p>Recently I was working on Google Maps markers and I had to handle multiple marker states like Loading, Pickup, Destination, and other information on the markers. Markers indicate single locations on the map. We can customize markers by inflating our own layout and based on our use-cases.</p><p><a href="https://developers.google.com/maps/documentation/android-sdk/marker">Markers | Maps SDK for Android | Google Developers</a></p><p>Here are some demo examples where custom makers are useful. The most common examples are markers on cab services. We have seen ETA on the marker, Location, direction, etc on the marker.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*uvpEqhFrNIsZL9ubX5Ph0g.png" /></figure><p>If you want to skip this then please use the below link for demo.</p><p><a href="https://github.com/droiddevgeeks/CustomMarker">droiddevgeeks/CustomMarker</a></p><p>lets take a simple example where we want to render the marker with the following use case. ( Mostly seen in cab services)</p><ol><li>Render marker with ETA ( like in Ola, Uber and other Cab services)</li><li>Render Normal marker</li><li>Render marker with other information</li></ol><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*suCEIQ4ftYsabUdu93GumQ.png" /></figure><blockquote>Define marker types. Type can be anything. It&#39;s totally based on your requirement like pickup marker, destination marker, eta marker, vehicle marker, marker with the image of the hotel, bank, petrol pump etc..</blockquote><pre>sealed class Type {<br>    object Pickup : Type()<br>    object Destination : Type()<br>}</pre><blockquote>Define the marker state: State represent current marker state like expanded( show info), Loading(Show loading), Moving(Dragging), Dropped( No information, only marker).</blockquote><pre>sealed class State {<br>    class Expanded(val info: String? = null) : State()<br>    object Dropped : State()<br>    object Loading : State()<br>    object Moving : State()<br>}</pre><p>Once you are done with marker type &amp; state, Now we have to create a custom marker view. This marker view will be basically responsible for inflating your marker layout, measuring marker layout params, displaying marker UI based on type &amp; state.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/da92707681eeae0733cc8747cd049420/href">https://medium.com/media/da92707681eeae0733cc8747cd049420/href</a></iframe><p>After creating a marker view, we will convert this view into BitmapDescriptor as MarkerOption from Google map accepts BitmapDescriptor.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/7f93b40258b80e0ab88413f42ff44361/href">https://medium.com/media/7f93b40258b80e0ab88413f42ff44361/href</a></iframe><p>Now how to use this custom marker</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/d7afc7612070705456ca64e40de3c1e4/href">https://medium.com/media/d7afc7612070705456ca64e40de3c1e4/href</a></iframe><p>here is a complete example in the Github link.</p><p><a href="https://github.com/droiddevgeeks/CustomMarker/blob/master/app/src/main/java/com/example/custommarker/marker/MapMarker.kt">droiddevgeeks/CustomMarker</a></p><p>Thanks for reading the article. You could check out my other interesting topics <a href="https://medium.com/@kishankr.maurya">here</a>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/225/1*7nNoed47OpFoeUER3CFBag.png" /></figure><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=742dc6035a43" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Android Interview Questions Part 3]]></title>
            <link>https://kishankrmaurya.medium.com/android-interview-questions-part-3-3a51ccabe253?source=rss-d4d9f7a8246b------2</link>
            <guid isPermaLink="false">https://medium.com/p/3a51ccabe253</guid>
            <category><![CDATA[android-interviews]]></category>
            <category><![CDATA[kotlin]]></category>
            <category><![CDATA[android]]></category>
            <category><![CDATA[interview-questions]]></category>
            <category><![CDATA[java]]></category>
            <dc:creator><![CDATA[Kishan Maurya]]></dc:creator>
            <pubDate>Mon, 30 Mar 2020 18:13:34 GMT</pubDate>
            <atom:updated>2020-03-31T04:46:48.670Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*J3XwgiEmDXNFJ_LE" /><figcaption>Photo by <a href="https://unsplash.com/@vantaymedia?utm_source=medium&amp;utm_medium=referral">Van Tay Media</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><p>This is part 3 of the android interview experience. You can also read my previous articles on android interviews.</p><p>Android Interview Questions <a href="https://medium.com/@kishankr.maurya/android-interview-questions-f2c97213e8bd">Part 1</a></p><p>Android Interview Questions <a href="https://medium.com/@kishankr.maurya/android-interview-questions-part-2-3df1d64ef63d">Part 2</a></p><ol><li>What is the difference between Val, var, const Val?</li><li>Internal keyword in kotlin?</li><li>What is the ViewModel factory and constructor of view model?</li><li>ViewModel with a single activity and multiple activities?</li><li>Use of Mediator live data?</li><li>MVVM vs MVP?</li><li>Task affinity?</li><li>Can GSP work without the internet?</li><li>Lambda Expression Vs Anonymous class?</li><li>Thread.sleep() &amp; wait()?</li><li>What are functional interfaces?</li></ol><blockquote>Recommended: Please solve it first, before moving on to the solution.</blockquote><p>There can multiple more accurate answers to the question. Based on my assumptions and learning, I am writing my answers.</p><blockquote>What is the difference between Val, var, const Val?</blockquote><p><strong><em>Var</em></strong>: <br>Kotlin’s keyword representing mutable, non-final variables. Once initialized, we’re free to mutate the data held by the variable.</p><p><strong>Const</strong> are compile-time constants. <br>Meaning that their value has to be assigned during compile time, unlike vals, where it can be done at runtime.</p><blockquote>Internal keyword in kotlin</blockquote><p>The internal visibility modifier means that the member is visible within the same module. <br>More specifically, a module is a set of Kotlin files compiled together:<br> so the module can an <strong>IntelliJ IDEA module</strong> or a <strong>Maven</strong> project.</p><p>When dealing with multi-module projects in Android, internal is an extremely convenient modifier.<br> It makes things visible everywhere in the current module, but not visible outside.</p><blockquote>What is the ViewModel factory and constructor of view model?</blockquote><pre>Implementations of <strong>ViewModelProviders.Factory </strong>interface is responsible to instantiate <strong>ViewModels</strong>. </pre><pre>If you add an argument in the constructor you have to create your own implementation of ViewModelProvider.<strong>Factory</strong> to create your <strong>ViewModel </strong>instance.<br> <br>ViewModelProviders.<strong>of() </strong>method internally creates default <strong>ViewModelProvider.Factory</strong> implementation for creating our <strong>ViewModel </strong>with <strong>no argument</strong>. </pre><pre>So when you add an argument in the constructor, the inner implementation of <strong>ViewModelProvider.Factory</strong> failed to initialize your <strong>ViewModel </strong>because of <strong>ViewModelProvider.Factory</strong> call the <strong>primary constructor</strong> for creating the <strong>ViewModel’s</strong> instance<br> <br>If your <strong>ViewModel</strong> has dependencies and you want to test your <strong>ViewModel </strong>then you should create your own <strong>ViewModelProvider.Factory</strong> and passed dependency through <strong>ViewModel </strong>constructor and give value to the <strong>ViewModelProvider.Factory </strong>instance.</pre><blockquote>ViewModel with a single activity and multiple activities?</blockquote><p>When you call ViewModelProviders.of(this), you actually create/retain a ViewModelStore which is bound to <strong>this</strong>,<strong> so different Activities have different ViewModelStore </strong>and <br>each ViewModelStore creates a different instance of a ViewModel using a given factory, so you can not have the same instance of a ViewModel in different ViewModelStores.</p><blockquote>Use of Mediator live data?</blockquote><p><strong>MediatorLiveData</strong> is a subclass of <strong>LiveData</strong> that can observe other LiveData objects and react to OnChanged events from them.</p><p>For example, if you have a LiveData object in your UI that can be updated from a<strong> local database or a network</strong>, then you can add the following sources to the MediatorLiveData object: <br> A LiveData object associated with the data stored in the database. <br> A LiveData object associated with the data accessed from the network. <br> <br> Your activity only needs to observe the MediatorLiveData object to receive updates from both sources.</p><p><a href="https://stackoverflow.com/questions/45679896/android-mediatorlivedata-observer/49880405">Android MediatorLiveData observer</a></p><blockquote>MVVM vs MVP?</blockquote><p>MVP :</p><pre>For each Activity/Fragment (View) we require a Presenter. <br>This is a hardbound rule. <br>The presenter holds the reference to the Activity and Activity Holds the reference to the presenter. 1:1 relationship and that&#39;s where the <strong>biggest issue</strong> lies.</pre><p>MVVM:</p><pre>Only View(Activity) holds the reference to ViewModel and not vice versa, <br>this solves our tight coupling issue. A single view can hold a reference to multiple ViewModels.<br> </pre><p>Since Presenters are hardbound to Views, writing unit tests becomes slightly difficult as there is a dependency of a View.<br> <br> ViewModels are even more Unit Test friendly as they just expose the state and hence can be independently tested without requiring the need for testing how data will be consumed, In short, there is no dependency of the View.</p><blockquote>Task affinity</blockquote><p><a href="https://medium.com/@veeresh.charantimath8/playing-with-android-task-affinity-and-launch-modes-5c36a0421e83">Playing with Android Task Affinity and Launch Modes</a></p><p>By default, all activities in your app have an affinity to the package name of your app.</p><p>If <strong>MyActivity</strong> have a different affinity, which in turn places it in a different stack we use a property called <strong>taskAffinity </strong>of the <strong>&lt;activity&gt;</strong> element<br> <br> <strong>MyActivity</strong> is placed in a different stack named <strong>MyActivity.container </strong>and the other stack where the rest of the activities live points to the package name of the app.</p><p>If I launch <strong>MyActivity2</strong> from my <strong>MyActivity</strong>, the former will be a part of <strong>MyActivity.container</strong> stack.</p><blockquote>Can GSP work without the internet?</blockquote><p>There is no <strong>internet</strong> connection required to <strong>use GPS</strong> services. Global positioning system (<strong>GPS</strong>) is available FREE of cost everywhere on earth. That’s the reason your car’s <strong>GPS can work</strong> even if there is no <strong>internet</strong> connectivity in car’s navigation system.</p><blockquote>Lambda Expression Vs Anonymous class</blockquote><p>In the anonymous classes, ‘<strong>this</strong>’ keyword resolves to the anonymous class itself, <br>whereas for lambda expression, ‘<strong>this</strong>’ keyword resolves to enclose class where lambda expression is written.<br> <br>An anonymous class object generates a separate class file after compilation<br>Java compiler compiles lambda expressions and converts them into the private method of the class.<br> <br>Anonymous classes can be used in case of more than one <strong>abstract method</strong> while a lambda expression specifically used for <strong>functional interfaces</strong><br> <br>Anonymous class is a class without a name. While lambda expression is a method without a name. (anonymous function).</p><p><a href="https://www.geeksforgeeks.org/difference-between-anonymous-inner-class-and-lambda-expression/">Difference between Anonymous Inner Class and Lambda Expression - GeeksforGeeks</a></p><blockquote>Thread.sleep() &amp; wait() method</blockquote><p>The fundamental difference is that <strong>wait() is from Object </strong>and sleep() is a static method of Thread.</p><p>The major difference is that <strong>wait() releases the lock </strong>while sleep() doesn’t release any lock while waiting.</p><p>wait() is used for inter-thread communication while sleep() is used to introduce a pause on execution, generally.</p><p>wait() should be called from inside synchronize or else we get an IllegalMonitorStateException, while sleep() can be called anywhere.</p><p>To start a thread again from wait(), you have to call notify() or notifyAll(). <br>As for sleep(), the thread gets started after a specified time interval.</p><blockquote>What are functional interfaces?</blockquote><p>A single method interface is also sometimes referred to as a <strong><em>functional interface</em></strong>. An interface is still a <em>functional interface</em> even if it contains the default and static methods, as long as the interface only contains a single unimplemented (abstract) method.</p><p><a href="http://tutorials.jenkov.com/java/lambda-expressions.html">Java Lambda Expressions</a></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*qNufQ8EAeIQ_uXRF" /><figcaption>Photo by <a href="https://unsplash.com/@helloquence?utm_source=medium&amp;utm_medium=referral">Helloquence</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><p>Thanks for reading. Soon I will post more articles on Android and core Java.<br>Till then happy learning and keep reading!</p><p>You could check out my other interesting topics <a href="https://medium.com/@kishankr.maurya">here</a>.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=3a51ccabe253" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Android Interview Questions Part 2]]></title>
            <link>https://kishankrmaurya.medium.com/android-interview-questions-part-2-3df1d64ef63d?source=rss-d4d9f7a8246b------2</link>
            <guid isPermaLink="false">https://medium.com/p/3df1d64ef63d</guid>
            <category><![CDATA[android]]></category>
            <category><![CDATA[java]]></category>
            <category><![CDATA[interview-questions]]></category>
            <dc:creator><![CDATA[Kishan Maurya]]></dc:creator>
            <pubDate>Mon, 30 Mar 2020 18:12:44 GMT</pubDate>
            <atom:updated>2020-03-30T18:12:44.891Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*H94fMFP0MFoFpjRb" /><figcaption>Photo by <a href="https://unsplash.com/@mkvandergriff?utm_source=medium&amp;utm_medium=referral">Maranda Vandergriff</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><p>In my personal opinion, a good way for preparing any kind of interview is that after the interview gets over, note down all the questions that were asked in the interview and try to find the solution for the questions that you were not able to answer at the interview time. So I am going to share a few of the questions.</p><p>You can also read a few questions from my previous article.</p><p><a href="https://medium.com/@kishankr.maurya/android-interview-questions-f2c97213e8bd">Android Interview Questions</a></p><ol><li>How to execute 5 API calls parallel and once all completed do the next task?</li><li>Flatmap vs compose?</li><li>What will happen if you don’t override toEquals() method?</li><li>What will happen if you Overriding only hashCode() method</li><li>HashTable vs ConcurrentHashMap?</li><li>LinkedHashMap and it&#39;s working?</li><li>How to create a copy of the object?</li><li>What is Deep copy and shallow copy?</li><li>What is a sparse array and how it is different from HashMap?</li><li>What is a handler thread?</li></ol><blockquote>Recommended: Please solve it first, before moving on to the solution.</blockquote><p>There can multiple more accurate answers to the question. Based on my assumptions and learning, I am writing my answers.</p><blockquote>How to execute 5 API calls parallel and once all completed do the next task?</blockquote><p><strong>CountDownLatch</strong> is used to make sure that a task waits for other threads before it starts. <br> CountDownLatch in Java is a kind of synchronizer which allows one Thread to wait for one or more Threads before starts processing.<br> When countdownlach reached 0 then it means all thread inside that has completed their task.</p><p><a href="https://www.geeksforgeeks.org/countdownlatch-in-java/">CountDownLatch in Java - GeeksforGeeks</a></p><p><strong>In Kotlin using async and Launch<br> </strong>Create 5 Async coroutines and creation of all these 5 async inside another launch or async coroutine.</p><pre> var job = launch { <br> val work1 = async { myparallelTask(1) } <br> val work2 = async { myparallelTask(2) } <br> val work3 = async { myparallelTask(3) } <br> val work4 = async { myparallelTask(4) } <br> val work25 = async { myparallelTask(5) } </pre><pre> val result = work1.await() + work2.await() + work3.await() +    work4.await() + work5.await() <br> <br>  withContext(UI) { result.toString() }</pre><pre> }</pre><pre>//the variable <strong>result</strong> is only available when both <strong>work1</strong> , <strong>work2, work3 ,work4 ,work5 </strong>are completed</pre><blockquote>Flatmap vs compose?</blockquote><pre><strong>compose</strong>() is a higher level abstraction: it operates on the entire stream, not individually emitted items.</pre><pre><strong>compose</strong>() executes immediately when you create the Observable stream.</pre><pre><strong>flatMap</strong>() executes when its onNext() is called, each time it is called. <br><strong>FlatMap()</strong> transforms each item, whereas compose() transforms the whole stream.</pre><pre><strong>flatMap</strong>() is necessarily less efficient because it has to create a new Observable every time onNext() is called. <br><strong>compose</strong>() operates on the stream as it is</pre><blockquote>What will happen if you don’t override toEquals() method when dealing with hashmap?</blockquote><p><a href="https://www.geeksforgeeks.org/override-equalsobject-hashcode-method/">Why to Override equals(Object) and hashCode() method ? - GeeksforGeeks</a></p><p>The contract between equals() and hashCode() is:<br>1) If two objects are equal, then they must have the same hash code.<br>2) If two objects have the same hash code, they may or may not be equal.</p><pre>//Creating two Objects with  same state</pre><pre>Geek g1 = <strong>new</strong> Geek(&quot;demo&quot;, 1);<br>Geek g2 = <strong>new</strong> Geek(&quot;demo&quot;, 1);</pre><pre>Map&lt;Geek, String&gt; map = <strong>new</strong> HashMap&lt;Geek, String&gt;();<br>map.put(g1, &quot;CSE&quot;);<br>map.put(g2, &quot;IT&quot;);</pre><p><strong>Overriding only the equals(Object) method?</strong></p><p>If we only override equals(Object) method, when we call <strong>map.put(g1, “CSE”);</strong> it will hash to some bucket location and when we call <strong>map.put(g2, “IT”);</strong> it will hash to some other bucket location because of different hashcode value as hashCode() method has not been overridden.</p><p><strong>Overriding only hashCode() method?</strong></p><pre>Map map = new HashMap();<br>map.put(“xyz”, “CSE”);<br>map.put(“xyz”, “IT”);</pre><p>When we call <strong>map.put(“xyz”, “CSE”);</strong> it will generate hashcode value and stores it to the bucket location that is specified with this address (hashcode value). And when we call <strong>map.put(“xyz”, “IT”);</strong> it generates same hashcode value as previous entry since key objects are same and hashCode() method has been overridden.</p><p>So it should replace first with second as per rule. But it didn’t. The reason is when it iterates through that bucket and seeks to find k such that k.equals(“xyz”) i.e. if searching key already exists. But it fails to find because equals(Object ) method has not been overridden. It is a violation of the rule of hashing.</p><blockquote>HashTable vs ConcurrentHashMap?</blockquote><pre>Hashtable uses single lock for whole data. At a time only 1 thread can read/write data in hash table</pre><pre>Hashtable performance is quite slow.</pre><pre>ConcurrentHashMap uses <strong>multiple locks</strong> on segment level instead of object level i.e. whole Map.</pre><pre>ConcurrentHashMap doesn’t throw a ConcurrentModificationException if one thread tries to modify it while another is iterating over it and does not allow null values.</pre><pre>ConcurrentHashMap returns Iterator, which<strong> fails-safe </strong>(i.e. iterator will make a copy of the internal data structure) on concurrent modification.</pre><blockquote>LinkedHashMap and it’s working?</blockquote><p><a href="https://www.javamadesoeasy.com/2015/02/linkedhashmap-custom-implementation.html">LinkedHashMap Custom implementation in java - How LinkedHashMap works internally with diagrams and full program</a></p><p><strong>LinkedHashMap</strong> is that it <strong>maintains the insertion order </strong>of key-value pairs. We will maintain double LinkedList for doing so.</p><p><strong>Entry&lt;K, V&gt; before, after </strong>— we keep track of newly added entry in LinkedHashMap, which helps us in <strong>maintaining insertion order</strong>.</p><p><strong>Next</strong> will be used to put the entry in same bucket location</p><p>Entry contains</p><pre>{<br> K<strong> key, </strong><br> V<strong> value,</strong><br> Entry&lt;K,V&gt; <strong>next </strong>(i.e. next entry on that location of bucket),<br> Entry&lt;K,V&gt;<strong> before </strong>and<br> Entry&lt;K,V&gt;<strong> after<br>}</strong></pre><blockquote>How to create a copy of the object?</blockquote><p>Object cloning refers to the creation of an exact copy of an object. It creates a new instance of the class of the current object and initializes all its fields with exactly the contents of the corresponding fields of this object.</p><p>Assignment operator : <br> If we use the <strong>assignment operator</strong> then it will create a<strong> copy of the reference variable</strong> and <strong>not the object.</strong></p><pre><strong>class</strong> Test{<br><strong>int</strong> x, y;<br>Test(){<br>x = 10;<br>y = 20;<br>}<br>}</pre><pre>Test ob1 = <strong>new</strong> Test();<br>// Creating a new reference variable ob2 pointing to same address as ob1<br>Test ob2 = ob1;</pre><pre>// Any change made in ob2 will be reflected in ob1<br>ob2.x = 100;</pre><p><strong>clone() method :</strong></p><blockquote>Every class that implements clone() should call <strong>super.clone()</strong> to obtain the cloned object reference.</blockquote><blockquote>The class must also implement <strong>java.lang.Cloneable interface</strong> whose object clone we want to create otherwise it will throw <strong>CloneNotSupportedException</strong> when clone method is called on that class’s object.</blockquote><pre><strong>class</strong> Test{<strong>int</strong> x, y;}</pre><pre>// Contains a reference of Test and implements clone with shallow copy.</pre><pre><strong>class</strong> Test2 <strong>implements</strong> Cloneable{<br><strong>int</strong> a;<br><strong>int</strong> b;<br>Test c = <strong>new</strong> Test();<br><strong>public</strong> Object clone() <strong>throws</strong> CloneNotSupportedException  {<br><strong>return</strong> <strong>super</strong>.clone();<br>}<br>}</pre><pre><strong>public</strong> <strong>class</strong> Main{</pre><pre><strong>public</strong> <strong>static</strong> <strong>void</strong> main(String args[]) <strong>throws </strong>CloneNotSupportedException{</pre><pre>Test2 t1 = <strong>new</strong> Test2();<br>t1.a = 10;<br>t1.b = 20;<br>t1.c.x = 30;<br>t1.c.y = 40;</pre><pre>// Creating a copy of object t1 and passing it to t2<br>Test2 t2 = (Test2)t1.clone();</pre><pre>// Change in primitive type of t2 will not be reflected in t1 fieldt2.a = 100;</pre><pre>// Change in object type field will be reflected in both t2 and t1(shallow copy)<br>t2.c.x = 300;</pre><pre>OutPut : </pre><pre>t1.a    10<br>t1.b   20<br>t1.c.x. 300    // here change in c state reflects in both t1 &amp; t2.<br>t1.c.y. 40</pre><pre>t2.a  100<br>t2.b  20<br>t2.c.x  300 <br>t2.c.y 40</pre><blockquote>What is Deep copy and shallow copy?</blockquote><p><strong>Shallow Copy</strong></p><pre><strong>Shallow copy</strong> is method of copying an object and is followed by default in cloning.</pre><pre>In this method the fields of an old object X are copied to the new object Y.</pre><pre>While copying the <strong>object type field</strong> the reference is copied to Y i.e object Y will point to same location as pointed out by X. If the field value is a primitive type it copies the value of the primitive type.</pre><pre><strong>public</strong> Object clone() <strong>throws</strong> CloneNotSupportedException  {</pre><pre><strong>return</strong> <strong>super</strong>.clone();</pre><pre>}</pre><p><strong>Deep Copy</strong> :</p><pre>If any object has other class ( A ) ref then while cloning we have create new object of Class A.</pre><pre><strong>public</strong> Object clone() <strong>throws</strong> CloneNotSupportedException{</pre><pre>// Assign the shallow copy to new reference variable t<br>Test2 t = (Test2)<strong>super</strong>.clone();</pre><pre>// Create a new object for the field <strong>c</strong> and assign it to shallow copy obtained to make it a deep copy<br>t.c = <strong>new</strong> Test();</pre><pre><strong>return</strong> t;<br>}</pre><p>Guess the output of the program</p><pre>class Stu{<br>Stu(String name){<br>this.name = name;<br>}<br>public String name;<br>}</pre><pre>public class Main {<br>public static void main(String[] args) throws Exception {</pre><pre>List&lt;Stu&gt; a = new ArrayList&lt;Stu&gt;();<br>a.add(new Stu(&quot;HI&quot;));<br>a.add(new Stu(&quot;HEllo&quot;));<br>a.add(new Stu(&quot;Welcome&quot;));</pre><pre>List&lt;Stu&gt; b = a;<br>List&lt;Stu&gt; c = new ArrayList(a);<br>a.add(new Stu(&quot;Medium&quot;));<br>a.get(2).name = &quot;MAC&quot;;</pre><pre>System.out.println(b.size());     //<strong>4<br></strong>System.out.println(c.size());    //<strong>3<br></strong>System.out.println(b.get(2).name);  //<strong>MAC<br></strong>System.out.println(c.get(2).name); // <strong>MAC<br></strong>}<br>}</pre><blockquote>What is a sparse array and how it is different from HashMap?</blockquote><p><strong>ArrayMap</strong> contains two small arrays instead of one in a HashMap. <br> The first array (Hash-Array) contains the specified hash keys in sorted order. <br> The second array (Key-Value Array) stores the keys and values of the objects according to the first array.</p><p>When we fetch an item, a <strong>binary-search</strong> is done on the Hash-Array to find a matching hash the index and then directly return the key-value pair from the second array (Key-Value Array). If the key in the second array (Key-Value Array), doesn’t match then a linearly walk is done over the second array (Key-Value Array) to resolve the collision.<br> <br> <br> <strong>SparseArray</strong> key is always primitive types. Sparse arrays can be used to replace hash maps when the key is a primitive type.</p><p><strong>SparseArray</strong> is designed to <strong>remove the auto-boxing</strong> problem (ArrayMap does not avoid the auto-boxing problem). This approach affects memory consumption.</p><pre><strong>SparseArray over HashMap is:</strong></pre><pre>More memory efficient by using primitives<br>No auto-boxing<br>Allocation-free</pre><pre><strong>Drawbacks:<br></strong>For large collections, it is slower<br>It only available for Android</pre><blockquote>What is handler thread?</blockquote><p><a href="https://www.oreilly.com/library/view/efficient-android-threading/9781449364120/ch08.html">Efficient Android Threading</a></p><p>HandlerThread sets up the Looper internally. <em>Handy class for starting a new thread that has a looper.</em></p><p>It is important to explicitly call <strong><em>quit</em></strong><em>()</em> on the HandlerThread in order to destroy it.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*hrzTulUHCL8hGE8u" /><figcaption>Photo by <a href="https://unsplash.com/@officestock?utm_source=medium&amp;utm_medium=referral">Sebastian Herrmann</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><p>Thanks for reading. Soon I will post more articles on Android and core Java.<br>Till then happy learning and keep reading!</p><p>You could check out my other interesting topics <a href="https://medium.com/@kishankr.maurya">here</a>.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=3df1d64ef63d" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[ViewStub: On-demand inflate view or lazily inflate layout resource]]></title>
            <link>https://proandroiddev.com/viewstub-on-demand-inflate-view-or-inflate-lazily-layout-resource-e56b8c39398b?source=rss-d4d9f7a8246b------2</link>
            <guid isPermaLink="false">https://medium.com/p/e56b8c39398b</guid>
            <category><![CDATA[ui]]></category>
            <category><![CDATA[viewstub]]></category>
            <category><![CDATA[androiddev]]></category>
            <category><![CDATA[android]]></category>
            <category><![CDATA[android-app-development]]></category>
            <dc:creator><![CDATA[Kishan Maurya]]></dc:creator>
            <pubDate>Fri, 03 Jan 2020 16:20:48 GMT</pubDate>
            <atom:updated>2020-01-03T16:23:24.278Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*FyI6t-BUzbPwZ8_tVUXKnw.png" /></figure><p>Sometimes while developing an application, we have encountered a situation like based on some logic, we have to render some new view in the layout that is rarely used. A general approach for this is to make View visibility GONE/VISIBLE.</p><p>So always inflating this rarely used view in a layout, is not a good idea and also it impacts the rendering of the layout.</p><p>So what to do in this case?</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*-KsWpVcQKivbS3Hs" /><figcaption>Photo by <a href="https://unsplash.com/@mero_dnt?utm_source=medium&amp;utm_medium=referral">Chinh Le Duc</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><p>So we have ViewStub for this.</p><h4>What is ViewStub?</h4><p>A ViewStub is an invisible, zero-sized View that can be used to lazily inflate layout resources at runtime. It is a dumb and lightweight view. It does not participate nor draws anything in the layout.</p><h4>When to use ViewStub?</h4><ol><li>When you want to inflate view lazily i.e on-demand or at runtime based on some logic.</li><li>When you don&#39;t want to render rarely used UI in layout always.</li></ol><h4>Benefits of ViewStub:</h4><ol><li>This can reduce memory usage and speed up rendering by loading the views only when they are needed.</li><li>Get rid of View GONE/VISIBLE</li></ol><h4>ViewStub vs Include Tag</h4><p>Include tag will just include the XML content’s in your layout.</p><p>ViewStub will be loaded only when you actually need it i.e when you set ViewStub visibility to <strong>true</strong> or call <strong>inflate</strong>() then only it will draw on UI.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/4f01674aa97d4b08f31ce356a3120201/href">https://medium.com/media/4f01674aa97d4b08f31ce356a3120201/href</a></iframe><h4>How ViewStub works :</h4><ol><li>When a ViewStub is made visible, or when inflate() is invoked, the layout resource is inflated.</li><li>The ViewStub then replaces itself in its parent with the inflated View or Views. Therefore, the ViewStub exists in the view hierarchy until setVisibility or inflate() is invoked.</li><li>The inflated view is added to the ViewStub&#39;s parent with the ViewStub&#39;s layout parameters.</li></ol><h4>How to use ViewStub in Android :</h4><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/4f01674aa97d4b08f31ce356a3120201/href">https://medium.com/media/4f01674aa97d4b08f31ce356a3120201/href</a></iframe><ul><li><strong>id</strong>: ViewStub defined can be found using the id.</li><li><strong>inflatedId:</strong> This attribute is used to set the id of the inflated View.</li><li><strong>layout:</strong> This attribute is used to supply an identifier for the layout resource to inflate.</li></ul><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/53fc06c91ae07fae729d8775dd9a4fe3/href">https://medium.com/media/53fc06c91ae07fae729d8775dd9a4fe3/href</a></iframe><p>When <em>inflate()</em> is invoked, the ViewStub is replaced by the inflated View and the inflated View is returned to its view hierarchy.</p><p><strong>Reference:<br></strong><a href="https://developer.android.com/reference/android/view/ViewStub.html">https://developer.android.com/reference/android/view/ViewStub.html</a><br><a href="https://medium.com/@sekarmohan77/android-viewstub-b03373ecf03a">https://medium.com/@sekarmohan77/android-viewstub-b03373ecf03a</a></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*0V0rgzIC4AK1NTpRY3fIqA.jpeg" /></figure><p>Thanks for reading. Soon I will post more articles on Android and core Java.<br>Till then happy learning and keep reading!</p><p>You could check out my other interesting topics <a href="https://medium.com/@kishankr.maurya">here</a>.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=e56b8c39398b" width="1" height="1" alt=""><hr><p><a href="https://proandroiddev.com/viewstub-on-demand-inflate-view-or-inflate-lazily-layout-resource-e56b8c39398b">ViewStub: On-demand inflate view or lazily inflate layout resource</a> was originally published in <a href="https://proandroiddev.com/">ProAndroidDev</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[AsyncLayoutInflater: On the way to making the UI thread responsive]]></title>
            <link>https://proandroiddev.com/asynclayoutinflater-on-the-way-to-the-ui-thread-to-be-responsive-743cb6cb201?source=rss-d4d9f7a8246b------2</link>
            <guid isPermaLink="false">https://medium.com/p/743cb6cb201</guid>
            <category><![CDATA[asynclayoutinflater]]></category>
            <category><![CDATA[ui]]></category>
            <category><![CDATA[android]]></category>
            <category><![CDATA[androiddev]]></category>
            <category><![CDATA[android-app-development]]></category>
            <dc:creator><![CDATA[Kishan Maurya]]></dc:creator>
            <pubDate>Tue, 31 Dec 2019 08:58:45 GMT</pubDate>
            <atom:updated>2019-12-31T09:05:53.638Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*-RGPHpQ3rKbsogyrLfwL5Q.png" /></figure><p>Recently I was working on Google Maps with custom marker layout and I was inflating custom marker layout and creating bitmap from that layout as MarkerOptions accepts bitmap. So layout inflation + bitmap generation was happening in main-thread (fragment). This could create unresponsiveness and jank.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/9231f949c36444bbe6ebca45c9eee966/href">https://medium.com/media/9231f949c36444bbe6ebca45c9eee966/href</a></iframe><p>so, I search for this scenario and found AsyncLayoutInflater.</p><p>What is AsyncLayoutInflater?</p><blockquote>Helper class for inflating layouts asynchronously.</blockquote><p>When to use AsyncLayoutInflater?</p><blockquote>This is intended for parts of the UI that are created lazily or in response to user interactions. This allows the UI thread to continue to be responsive &amp; animate while the relatively heavy inflate is being performed.</blockquote><p>How to use AsyncLayoutInflater?</p><p>Construct an instance of <em>AsyncLayoutInflater</em> on the UI thread and call <em>inflate(int, ViewGroup, OnInflateFinishedListener)</em>. The AsyncLayoutInflater.OnInflateFinishedListener will be invoked on the UI thread when the inflate request has completed.</p><p>The inflate function takes 3 parameters. First is your layout resource, second is an optional view intended to be a parent of inflated hierarchy and third is an OnInflateFinishedListener, which is a callback.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/b3d5525ba8e17d82f7f3532052d36353/href">https://medium.com/media/b3d5525ba8e17d82f7f3532052d36353/href</a></iframe><p>It is equivalent to calling <a href="http://www.iut-fbleau.fr/docs/android/reference/android/view/LayoutInflater.html#inflate(int,%20android.view.ViewGroup,%20boolean)">inflate(int, ViewGroup, boolean)</a> with <strong>attachToRoot</strong> set to false.</p><p>If the layout that is trying to be inflated cannot be constructed asynchronously for whatever reason, <a href="http://www.iut-fbleau.fr/docs/android/reference/android/support/v4/view/AsyncLayoutInflater.html">AsyncLayoutInflater</a> it will automatically fall back to inflating on the UI thread. <strong>So App crash will never occur due to this.</strong></p><p>Things to remember while using AsyncLayoutInflater</p><ul><li>parents function <em>generateLayoutParams()</em> has to be thread-safe</li><li>all views being constructed must not create any <em>Handler</em>s or call Looper.myLooper() function</li><li>no support for setting <em>LayoutInflater.Factory</em> nor <em>LayoutInflater.Factory2</em></li><li>no support for inflating layouts containing fragments</li></ul><p><strong>References</strong> : <br><a href="https://github.com/amalChandran/asyncLayoutInflator">https://github.com/amalChandran/asyncLayoutInflator</a><br><a href="https://www.youtube.com/watch?v=ZETNOieGZLA&amp;feature=youtu.be">https://www.youtube.com/watch?v=ZETNOieGZLA&amp;feature=youtu.be</a><a href="https://medium.com/@lupajz/asynchronous-layout-inflation-7cbca2653bf"><br>https://medium.com/@lupajz/asynchronous-layout-inflation-7cbca2653bf</a></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*uGQYowZpDbJ8SFTi" /><figcaption>Photo by <a href="https://unsplash.com/@aaronburden?utm_source=medium&amp;utm_medium=referral">Aaron Burden</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><p>Thanks for reading. Soon I will post more articles on android, core java.<br>till then happy learning… keep reading… :)</p><p>You could check out my other interesting topics <a href="https://medium.com/@kishankr.maurya">here</a>.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=743cb6cb201" width="1" height="1" alt=""><hr><p><a href="https://proandroiddev.com/asynclayoutinflater-on-the-way-to-the-ui-thread-to-be-responsive-743cb6cb201">AsyncLayoutInflater: On the way to making the UI thread responsive</a> was originally published in <a href="https://proandroiddev.com/">ProAndroidDev</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Directory Management using cd vs pushd]]></title>
            <link>https://medium.com/mindorks/directory-management-using-cd-vs-pushd-6af9c96732e4?source=rss-d4d9f7a8246b------2</link>
            <guid isPermaLink="false">https://medium.com/p/6af9c96732e4</guid>
            <category><![CDATA[pushd]]></category>
            <category><![CDATA[terminal]]></category>
            <category><![CDATA[change-directory]]></category>
            <category><![CDATA[popd]]></category>
            <category><![CDATA[cmd]]></category>
            <dc:creator><![CDATA[Kishan Maurya]]></dc:creator>
            <pubDate>Sat, 07 Dec 2019 18:28:03 GMT</pubDate>
            <atom:updated>2019-12-07T18:28:03.886Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/300/1*mUdcxhR26ryWwE_vvwxW0Q.png" /></figure><p>The most common way to change directory from the command line is cd<br>How do we change the directory?</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*9jyjyhCE_bRtHo2VeKdHJg.png" /><figcaption>change directory using cd command</figcaption></figure><p>The above image shows the changing directory in a sequential manner like going one step down each time.</p><p>let suppose from my current directory( /Users/kishankumarmaury ), <br>I go to (/Downloads/GOJEK) and from there I go to (/Development/Node)</p><pre>kishankumarmaurya@Manavs-MacBook-Pro ~ % pwd<br>/Users/kishankumarmaurya<br>kishankumarmaurya@Manavs-MacBook-Pro ~ % cd ~/Downloads/GOJEK<br>kishankumarmaurya@Manavs-MacBook-Pro GOJEK % pwd<br>/Users/kishankumarmaurya/Downloads/GOJEK<br>kishankumarmaurya@Manavs-MacBook-Pro GOJEK % cd ~/Development/Node</pre><pre>kishankumarmaurya@Manavs-MacBook-Pro NodeLearning % pwd<br>/Users/kishankumarmaurya/Development/Node</pre><p>so present working directory will be</p><pre>/Users/kishankumarmaurya/Development/Node</pre><p>Now if I want to go back to GOJEK folder then I have to use cd command with full path.</p><p>Painful thing is that we have to remember the path of the previous directory.</p><p>Thanks to <strong>pushd</strong> and <strong>popd</strong> command from saving us to remember the directory path.</p><p>How pushd and popd works?</p><blockquote>pushd command is used to save the current directory into a stack and move to a new directory. <br>popd can be used to return back to the previous directory that is on top of the stack.</blockquote><blockquote><em>pushd</em> and <em>popd</em> work according to the “LIFO” (last in, first out) principle</blockquote><p><strong>Example of pushd :</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*doA_jIosbajcwv0oLbLNsg.png" /></figure><pre>Stack Information</pre><pre>~/Development/Node/NodeLearning <br>~/Development/Node <br>~/Downloads/GOJEK/DRIVER <br>~/Downloads/GOJEK <br>~</pre><p>Now I want to make ( /Development/Node ) as on Top<br>use</p><pre>pushd +1</pre><pre>After this command stack will look like this<br>~/Development/Node <br>~/Downloads/GOJEK/DRIVER <br>~/Downloads/GOJEK <br>~ <br>~/Development/Node/NodeLearning</pre><pre>pushd +2  //will move /Downloads/GOJEK at top</pre><pre>~/Downloads/GOJEK<br>~ <br>~/Development/Node/NodeLearning <br>~/Development/Node <br>~/Downloads/GOJEK/DRIVER</pre><p><strong>Example of popd :</strong></p><pre>~/Development/Node/NodeLearning<br>~/Development/Node <br>~/Downloads/GOJEK/DRIVER <br>~/Downloads/GOJEK <br>~</pre><pre>popd</pre><pre>~/Development/Node <br>~/Downloads/GOJEK/DRIVER <br>~/Downloads/GOJEK <br>~<br>--------------------------------------------------------------------</pre><pre>Now let say we have stack</pre><pre>~/Development/Node <br><strong>~/Downloads/GOJEK/DRIVER </strong><br>~/Downloads/GOJEK <br>~</pre><pre>and we hit command <strong>popd +1</strong> then stack state will be<br>~/Development/Node <br>~/Downloads/GOJEK <br>~<br>--------------------------------------------------------------------</pre><p>To know the stack of directories use <strong>dirs </strong>and to clear entire stack use<strong> dirs -c</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*oktdkU68SnlhqkIej1j3NQ.png" /><figcaption>Stack Information</figcaption></figure><p>Thanks for reading. Soon I will post more articles on android, core java.<br>till then happy learning… keep reading… :)</p><p>You could check out my other interesting topics <a href="https://medium.com/@kishankr.maurya">here</a>.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=6af9c96732e4" width="1" height="1" alt=""><hr><p><a href="https://medium.com/mindorks/directory-management-using-cd-vs-pushd-6af9c96732e4">Directory Management using cd vs pushd</a> was originally published in <a href="https://medium.com/mindorks">MindOrks</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
    </channel>
</rss>