<?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 Karandeep Atwal on Medium]]></title>
        <description><![CDATA[Stories by Karandeep Atwal on Medium]]></description>
        <link>https://medium.com/@karanatwal?source=rss-286e3829fe61------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/0*LvyBr3UE-MK0f3u-.</url>
            <title>Stories by Karandeep Atwal on Medium</title>
            <link>https://medium.com/@karanatwal?source=rss-286e3829fe61------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Tue, 01 Dec 2026 07:18:21 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@karanatwal/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[FirePush — A Lightweight Kotlin Library for sending FCM push notifications like a pro.]]></title>
            <link>https://medium.com/mindorks/firepush-a-lightweight-kotlin-library-for-sending-fcm-push-notifications-like-a-pro-7459b011720f?source=rss-286e3829fe61------2</link>
            <guid isPermaLink="false">https://medium.com/p/7459b011720f</guid>
            <category><![CDATA[push-notification]]></category>
            <category><![CDATA[coroutine]]></category>
            <category><![CDATA[kotlin]]></category>
            <category><![CDATA[fcm]]></category>
            <category><![CDATA[android]]></category>
            <dc:creator><![CDATA[Karandeep Atwal]]></dc:creator>
            <pubDate>Sat, 08 Jun 2019 16:43:41 GMT</pubDate>
            <atom:updated>2019-06-08T16:43:41.611Z</atom:updated>
            <content:encoded><![CDATA[<h3>FirePush — A Lightweight Kotlin Library for sending FCM push notifications like a pro.</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/968/1*nRX4FPCjDMrEHenRTDesjQ.png" /></figure><p>Summer’s at its peak and so is the heat, but don’t worry I came up with a coolest kotlin library <strong>FirePush.<br></strong>You may be wandering about <em>what’s the coolest in this</em> ? <br>Because you can now send push notifications from your android app to any FCM supported platform like a pro. <br><em>How like pro ? </em>We will find it later below<em>.<br>How lightweight? </em>I have used only <strong>Kotlin</strong> inbuilt libraries and <strong>Coroutines</strong> for IO operations.</p><p>If you look around googling Send push notification from android device, you will end up with a lot of PHP code on internet and you have to add key pairs in a JSONObject and put them in params and make a http request so and so….</p><p>While I was working on a project I have some cases where I have to send push notification from device end e.g like while chatting, event based push and every time I have to hit a http request and wait for the result, Then I thought that there might be a library about the same, I googled , found some java libraries but some were outdated or were not like i was looking for, So I decided to make a library that fits up with my needs. See what I made -</p><p><a href="https://github.com/karanatwal/FirePush">karanatwal/FirePush</a></p><p>Now, Long story short. For sending push you just need to do the following first.</p><p>Step 1. In root build.gradle add -</p><pre>allprojects {<br>  repositories {<br>	  ...<br>	  maven { url &#39;https://jitpack.io&#39; }<br>  }<br>}</pre><p>and add below dependency -</p><pre>dependencies {<br>	  implementation &#39;com.github.karanatwal:FirePush:1.0.0&#39;<br>}</pre><p><strong>Step 2.</strong> Get Server Key and add below in your Application’s/Activity’s onCreate :</p><pre>override fun onCreate(savedInstanceState: Bundle?) {  <br>    super.onCreate(savedInstanceState)<br>    Fire.init(&quot;YOUR_SERVER_KEY_HERE&quot;)<br> }</pre><p>You know <strong>Server Key</strong>? You can found yours on Firebase Console, See -</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*FNckGxbEFFtAAYW1v0djtw.png" /></figure><p><strong>Step 3 (&amp; Final Step 😎 Isn’t cool ?). Pull your trigger and FIRE..</strong></p><pre>Fire.create()  <br>        .setTitle(&quot;Hello Ladies!!&quot;)  <br>        .setBody(&quot;This is just a body !&quot;)  <br>        .setBadgeCount(2)  <br>        .setClickAction(&quot;&quot;)  <br>        .setAndroidChannelId(&quot;&quot;)  <br>        .setColor(&quot;&quot;)  <br>        .setIcon(&quot;&quot;)  <br>        .setSound(&quot;&quot;)  <br>        .setTag(&quot;&quot;)  <br>        .setPriority(FirePushPriority.HIGH)  <br>        .addData(&quot;key&quot;,&quot;value&quot;)  <br>        .addData(HashMap())<br>        .setCallback { pushCallback, exception -&gt;  <br>         //get response here<br>        }<br>        .toTopic(&quot;&quot;)// or toIds or toCondition  <br>        .push()</pre><p>You can send either to registration tokens or topic or a condition.</p><p>On other side you can receive notification in onMessageReceived callback, when your app will be in foreground. And for background System Tray of app will handle it for you. You can get data object in intent of the activity whichever will get opened on click of notification.</p><h4>Data Payload Only based Push :</h4><p>Here we can send data only push in which there is no Notification object, only data object with custom key-pairs. Such push notifications directly awakes your android app and onMessageReceived callback is triggered even app is killed.</p><blockquote>Note: This happens only in Android. Not for iOS.</blockquote><p>For Sending data object only do like below -</p><pre>Fire.createDataPayloadOnly()  <br>        .setPriority(FirePushPriority.HIGH)  <br>        .add(&quot;key&quot;,&quot;value&quot;)  <br>        .add(HashMap()) //or use this<br>        .setCallback { pushCallback, exception -&gt;  <br>         //get response here<br>        }<br>        .toTopic(&quot;&quot;)// or toIds or toCondition  <br>        .push()</pre><p>You can go through the sample in my <a href="https://github.com/karanatwal/FirePush">Github</a> repo. Thanks, I would appreciate for new Ideas or additions, Pull requests are welcomed.<br><a href="https://karanatwal.github.io/">Karandeep Atwal</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=7459b011720f" width="1" height="1" alt=""><hr><p><a href="https://medium.com/mindorks/firepush-a-lightweight-kotlin-library-for-sending-fcm-push-notifications-like-a-pro-7459b011720f">FirePush — A Lightweight Kotlin Library for sending FCM push notifications like a pro.</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>
        <item>
            <title><![CDATA[Try-catch v/s Null-check in Android.]]></title>
            <link>https://medium.com/mindorks/try-catch-v-s-null-check-in-android-41ba3eba3b65?source=rss-286e3829fe61------2</link>
            <guid isPermaLink="false">https://medium.com/p/41ba3eba3b65</guid>
            <category><![CDATA[software-development]]></category>
            <category><![CDATA[android]]></category>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[androiddev]]></category>
            <category><![CDATA[android-app-development]]></category>
            <dc:creator><![CDATA[Karandeep Atwal]]></dc:creator>
            <pubDate>Fri, 18 Aug 2017 12:45:04 GMT</pubDate>
            <atom:updated>2017-08-21T04:15:17.412Z</atom:updated>
            <content:encoded><![CDATA[<p>I believe most of the productive developers are the lazy ones 🤣 . Most of us uses <a href="http://www.jsonschema2pojo.org/">JSON2POJO</a> , <a href="http://jakewharton.github.io/butterknife/">ButterKnife</a> etc. to save time. No doubt , it’s good. But sometimes that laziness can slow down your app.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/698/1*c2S5-Gw-ostMw_h5vXDn6Q.gif" /><figcaption>try-catch while parsing JSON</figcaption></figure><h3>What we know about <em>Try-catch</em> ?</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/485/1*ZN8A-mVH24pf1u_seEhUvQ.jpeg" /></figure><p>Once in an Interview with a fresher, I asked about<em> try-catch</em> and got funniest reply -</p><blockquote>we put that code in <strong><em>try{}</em></strong> that we are afraid of it might be null or it can cause app crash &amp; we catch error in <strong><em>catch{}.</em></strong></blockquote><p>But we can never catch <strong>Errors </strong>😒<strong> . </strong>Mostly newbies mistakenly takes <strong>Errors</strong> &amp; <strong>Exceptions</strong> as same . Well , We were talking about Try-catch and Null Check.</p><p>In practice I see exception often used out of laziness. Instead of properly handling an error condition at the location where it occurs, people find it easier to throw an exception and catch it somewhere downstream, often resulting in spitting out some incomprehensible error message to the user.</p><h3>Performance :</h3><p><a href="https://twitter.com/clemensv">Clemens Vasters</a> tweets some time ago -</p><h3>Clemens Vasters 🇪🇺 on Twitter</h3><p>You know what really sucks for performance? &quot;throw&quot; when it&#39;s a predictable, intentional outcome of processing and not a true exception.</p><p>Below we can see what happen when we write →</p><pre>try{</pre><pre>   //some exception</pre><pre>}catch(Exception e){<br>    e.printstacktrace();<br>   //Log.e(&quot;&quot;,e.getMessage());<br>}</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/792/1*HuDhEM9tfV9t17WwSxmQyw.png" /><figcaption>Taken from <a href="http://mattwarren.org/2016/12/20/Why-Exceptions-should-be-Exceptional/">http://mattwarren.org/2016/12/20/Why-Exceptions-should-be-Exceptional/</a></figcaption></figure><p>Exceptions do take extra memory, as well as time, to catch. It is ALWAYS better to test for null if it’s a possible value. Another thing to consider it that it’s simply less code and more readable to do the null test. Usually having <em>try/catch</em> blocks adds essentially no overhead to your code for the normal case, but when the exception is triggered it’s quite expensive.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/488/1*n5AVlxlA38BrVwd9wpBBPw.png" /></figure><p>So what do we learned from above ? In one line -</p><blockquote><strong>Exceptions are, as their name implies, to be used only for exceptional conditions, they should never be used for ordinary control flow.</strong></blockquote><h3>Moral ?</h3><p>There are thousands cases where your code can go wrong: cannot connect to database, IO Exception, Network error… If you deal with them one by one (like the null check here), it would be too much of a hassle</p><p>but, if you know that variable/object can be null or it can cause a NullPointerException so better is to check rather than showing laziness (Ctrl+alt+t+6) 💻 (<em>try-catch</em> shortcut in <strong>Android Studio</strong>) 😜</p><p><em>Happy Coding.. 😈</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=41ba3eba3b65" width="1" height="1" alt=""><hr><p><a href="https://medium.com/mindorks/try-catch-v-s-null-check-in-android-41ba3eba3b65">Try-catch v/s Null-check in Android.</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>