<?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 Ayush Jain on Medium]]></title>
        <description><![CDATA[Stories by Ayush Jain on Medium]]></description>
        <link>https://medium.com/@ayushjain0801?source=rss-8da9b8617d4------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*_xgk4CsDPgiAxbGpGynLVQ.jpeg</url>
            <title>Stories by Ayush Jain on Medium</title>
            <link>https://medium.com/@ayushjain0801?source=rss-8da9b8617d4------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Thu, 19 Nov 2026 01:43:45 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@ayushjain0801/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[Booking My First Car — Honda Elevate ZX CVT!]]></title>
            <link>https://medium.com/@ayushjain0801/booking-my-first-car-honda-elevate-zx-cvt-ecaac4f20b26?source=rss-8da9b8617d4------2</link>
            <guid isPermaLink="false">https://medium.com/p/ecaac4f20b26</guid>
            <category><![CDATA[cár]]></category>
            <dc:creator><![CDATA[Ayush Jain]]></dc:creator>
            <pubDate>Sat, 18 Jan 2025 16:28:59 GMT</pubDate>
            <atom:updated>2025-01-18T16:28:59.082Z</atom:updated>
            <content:encoded><![CDATA[<h3>Booking My First Car — Honda Elevate ZX CVT!</h3><p>Hey everyone,</p><p>After two months of deep diving into the world of cars, watching countless videos, and reading reviews, I’ve finally booked my first car! Here’s a detailed breakdown of my journey:</p><h3>The Budget and Research Phase</h3><p>Initially, my budget was around upto <strong>₹13 lakhs</strong>, but as I researched more and explored better options, I stretched it to <strong>₹14–16 lakhs</strong>. As a complete newbie, I spent hours learning about different aspects like:</p><ul><li><strong>Transmissions</strong> and their pros/cons.</li><li><strong>Safety ratings</strong>, engine types, car dynamics, and platforms.</li><li>And yes, even the small details like boot space and headroom!</li></ul><p>My priority was to get a car I could keep for the long haul, as I’m not into aggressive or “boom-blast” driving. I went for Automatic Transmission because “she wants it :)”</p><h3>Which Automatic Transmission to go with?</h3><p>Here’s what I learned:</p><ol><li><strong>DCA/DCT: </strong>Amazing for highways, but not ideal for long-term city usage. TATA’s wet DCA (in Nexon/Altroz) is promising, but reviews (Team BHP) mention reliability concerns. These might be resolved now, but DCA still made me hesitant</li><li><strong>AMT: </strong>Reliable and fuel-efficient but doesn’t offer the smoothness of other automatics.</li><li><strong>AT (Torque Converter): </strong>Old, proven technology but not fuel-efficient and “petrol peeta hai.”</li><li><strong>CVT: </strong>No instant power boost like AT/DCA, but fun to drive, smooth, and long-lasting. Slightly less fuel-efficient than AMT but better than DCA/AT for city traffic.The Contenders</li></ol><p>Here are the cars I considered:</p><p><strong>TATA Nexon DCA</strong></p><ul><li>Priced around <strong>₹14.70 lakhs on-road</strong>.</li><li>Reliable wet DCA but still a DCA (not ideal for city longevity).</li><li>Strong contender until the test drive.</li></ul><p><strong>Mahindra XUV3x0 AX5L</strong></p><ul><li>Priced at <strong>₹17.00 lakhs on-road</strong> with a <strong>6–8 week waiting period</strong>.</li><li><strong>Super small boot space</strong>, making it impractical for me.</li><li>Spending <strong>₹17 lakhs on a compact car</strong> felt hard to justify.</li><li>We did not like the design much.</li></ul><p><strong>Skoda Kushaq</strong></p><ul><li>Looked promising but ridiculously overpriced.</li><li>Nothing exciting in terms of features, and the showroom didn’t even have a car for display.</li></ul><p>At this point, I was leaning toward the <strong>Nexon</strong>, but…</p><h3>The Turning Point</h3><p>I decided to take a <strong>Honda Elevate ZX CVT</strong> test drive, and it changed everything!</p><ul><li>Loved the <strong>look, space, boot size, and feel</strong> of the car.</li><li>While it doesn’t have a turbo engine, that’s fine for my driving style.</li></ul><p>The initial quote is around <strong>₹20.6 lakhs on-road</strong>, but after there is plenty room for negotiation.</p><p>Since we are spending around ** lakh, in this budget we have other options like kushaq/taigun 1.0. Creta/seltos lower variants but still I believe elevate wins on this price. Skoda 1.0 is ok deal but again AT and I will prefer 4 cylinder over 3.</p><h3>Showroom Experiences</h3><p><strong>Mahindra</strong></p><ul><li><strong>First visit (alone):</strong> I waited for a long time before the SA arrived. Instead of explaining the car features, I had to ask all the questions. The SA asked for my budget, but I insisted on knowing the car first. After two days, I called for a follow-up, and he didn’t even remember who I was.</li><li><strong>Second visit (with wife):</strong> The experience improved at another showroom. We were offered tea/coffee, and the SA was helpful but still pushed for the top-end variant. If you’re not knowledgeable, Mahindra might upsell you aggressively.</li></ul><p><strong>TATA</strong></p><ul><li>The best experience overall! The SA explained all variants, from base to top-end, and didn’t push unnecessarily.</li></ul><p><strong>Honda</strong></p><ul><li>Whitefeild honda SA literarily told that there is no car to show but after I spoke to some manager about this same SA showed me demo vehicle. Later On pricing and discount he asked me to call me back later since he needs to check. Woow, I simple left but of-course I went other show room then.</li><li>Next Showroom, The SA lacked knowledge about the few electrical features and deferred some questions. While the experience was okay, it didn’t leave a strong impression. However I was getting followup calls.</li></ul><h3>The Final Decision</h3><p>I’m going with the <strong>Honda Elevate ZX CVT</strong> in pearl white.</p><p><strong>I will post more detail on discount and quotation and color (Still Negotiating). Stay Tuned !!</strong></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=ecaac4f20b26" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[A beginner guide to “Flutter”]]></title>
            <link>https://medium.com/@ayushjain0801/what-can-flutter-do-for-me-bce4c7926167?source=rss-8da9b8617d4------2</link>
            <guid isPermaLink="false">https://medium.com/p/bce4c7926167</guid>
            <category><![CDATA[mobile-app-development]]></category>
            <category><![CDATA[flutter]]></category>
            <dc:creator><![CDATA[Ayush Jain]]></dc:creator>
            <pubDate>Tue, 24 Apr 2018 13:12:38 GMT</pubDate>
            <atom:updated>2018-04-24T14:36:20.393Z</atom:updated>
            <content:encoded><![CDATA[<p>Hello guys,</p><p><em>There is no code in this post. You are reading it on your risk.</em></p><p>If you are an android developer or an iOS developer till now you must have heard about <a href="https://flutter.io/">flutter</a>, if not please check <a href="https://flutter.io/">this</a> now. Anyway I am doing mobile app development from last 3 years and I am using swift and java/kotlin. There are hell lot of things in native app development. But again as I am hearing flutter, flutter, flutter every where so I started with it and give myself a chance as it was my first step into hybrid kinda thing.</p><p>I started and I am glad I used it ,the same app with 50% — 60% less code with less effort. what? HELL YEAH…I am very new in flutter so I think I don’t want to write anything wrong but I can provide some links those are very useful.</p><p><strong>1 : (blog)</strong></p><p><a href="https://medium.com/flutter-io/zero-to-one-with-flutter-43b13fd7b354">https://medium.com/flutter-io/zero-to-one-with-flutter-43b13fd7b354</a></p><p><a href="https://hackernoon.com/develop-your-first-application-with-flutter-60c4308d18b7">Develop your first Application with Flutter</a></p><p><a href="https://www.youtube.com/watch?v=jF0kD7lxTTw"><strong>2 :</strong></a><strong> (video)</strong></p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fwww.youtube.com%2Fembed%2FjF0kD7lxTTw%3Ffeature%3Doembed&amp;url=http%3A%2F%2Fwww.youtube.com%2Fwatch%3Fv%3DjF0kD7lxTTw&amp;image=https%3A%2F%2Fi.ytimg.com%2Fvi%2FjF0kD7lxTTw%2Fhqdefault.jpg&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=youtube" width="854" height="480" frameborder="0" scrolling="no"><a href="https://medium.com/media/79d763e3583de2c9d3b75bbb507d5e39/href">https://medium.com/media/79d763e3583de2c9d3b75bbb507d5e39/href</a></iframe><p><strong>3: (blog)</strong></p><p><a href="https://medium.com/flutter-io/beautiful-animated-charts-for-flutter-164940780b8c">Beautiful, animated charts for Flutter</a></p><p><strong>4: (blog)</strong></p><p><a href="https://proandroiddev.com/flutter-from-zero-to-comfortable-6b1d6b2d20e">Flutter : From Zero To Comfortable</a></p><p><strong>5: PODCAST (audio)</strong></p><p><a href="http://fragmentedpodcast.com/tag/flutter/">Flutter - Fragmented</a></p><p><strong>6: official DOCS, very well explained</strong></p><p><a href="https://flutter.io/tutorials/">Flutter Tutorials - Flutter</a></p><p><strong>7: (video)</strong></p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fwww.youtube.com%2Fembed%2F1BXg4wfB9pA%3Ffeature%3Doembed&amp;url=http%3A%2F%2Fwww.youtube.com%2Fwatch%3Fv%3D1BXg4wfB9pA&amp;image=https%3A%2F%2Fi.ytimg.com%2Fvi%2F1BXg4wfB9pA%2Fhqdefault.jpg&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=youtube" width="854" height="480" frameborder="0" scrolling="no"><a href="https://medium.com/media/73d09c4d9907e73d5d6d82123dfff7db/href">https://medium.com/media/73d09c4d9907e73d5d6d82123dfff7db/href</a></iframe><p>These are some links I found useful as a new newbie, but I would love to know some more cool new stuff if you got. Please add those on comments.</p><p>Thanks for reading this article. Show some support if you found it helpful and gimme some claps. It means a lot to me. Please mention any other possible ways if you think.</p><p>Also, Let’s become friends on <a href="http://linkedin.com/in/ayush-jain1%20Profile%20URL">Linkedin</a>, <a href="https://github.com/stAyushJain">GitHub</a> and <a href="https://www.facebook.com/ayush.jain.754918">Facebook</a>.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=bce4c7926167" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Making Your App Location-Aware]]></title>
            <link>https://medium.com/@ayushjain0801/making-your-app-location-aware-d228a47a5915?source=rss-8da9b8617d4------2</link>
            <guid isPermaLink="false">https://medium.com/p/d228a47a5915</guid>
            <category><![CDATA[android-app-development]]></category>
            <dc:creator><![CDATA[Ayush Jain]]></dc:creator>
            <pubDate>Sun, 03 Sep 2017 11:24:00 GMT</pubDate>
            <atom:updated>2017-09-03T11:24:00.990Z</atom:updated>
            <content:encoded><![CDATA[<p>In this article we will learn how location updates work when targeting “N” (or lower) but running on an “O” device.</p><p>Along with new features and capabilities, Android 8.0 (API level 26) includes a variety of system and API behavior changes like background execution limit, app shortcuts, background location updates limit, Alert windows …etc. Today we will talk about the Background Location Limits on android “O”. In an effort to reduce power consumption, Android 8.0 limits how frequently background apps can retrieve the user’s current location. Apps can receive location updates only a few times each hour. So we can get all frequent location updates if our application is in foreground on a device running Android 8.0 (API level 26), the location update behavior is the same as on Android 7.1.1 (API level 25) and lower. if device running Android 8.0 and app is in background then we have handle it from our side as we can’t run a background service at all like before because now it will throw <strong>IllegalStateException exception. </strong>Before getting started let me clear it your app is considered to be in the foreground if any of the following is true:</p><ul><li>It has a visible activity, whether the activity is started or paused.</li><li>It has a foreground service.</li><li>Another foreground app is connected to the app, either by binding to one of its services or by making use of one of its content providers.</li></ul><p>Now we will make an android application and will see how location updates work.</p><p>add play services dependency on your gradle file</p><pre>compile &#39;com.google.android.gms:play-services-location:11.0.0&#39;</pre><p>in your manifest file add FINE_LOCATION permission</p><pre>&lt;uses-permission android:name=&quot;android.permission.ACCESS_FINE_LOCATION&quot;/&gt;</pre><p>Now make an activity class and a service class. In your activity class make sure to check permissions as required from API 24 :</p><p><strong>The Service class :</strong></p><p>We will make an a service class named LocationUpdatesService, inside onCreate method we will initialize our FusedLocationClient and make a location request. Inside LocationCallback we will check that our service is in background or foreground.</p><pre>public class LocationUpdatesService extends Service{<br><br>    @Override<br>    public void onCreate() {<br>        super.onCreate();<br>//        init FusedLocationProviderClient<br>        mFusedLocationClient = LocationServices.<em>getFusedLocationProviderClient</em>(this);</pre><pre>//        init and set LocationCallBack<br>        mLocationCallback = new LocationCallback()<br>        {<br>            @Override<br>            public void onLocationResult(LocationResult locationResult) {<br>                super.onLocationResult(locationResult);<br><br>                Intent intent = new Intent(<em>ACTION_BROADCAST</em>);<br>                mLocation = locationResult.getLastLocation();<br>                intent.putExtra(<em>EXTRA_LOCATION</em>, locationResult.getLastLocation());<br>                LocalBroadcastManager.<em>getInstance</em>(getApplicationContext()).sendBroadcast(intent);<br><br>                // Update notification content if running as a foreground service.<br>                if (serviceIsRunningInForeground(LocationUpdatesService.this)) {<br>                    mNotificationManager.notify(<em>NOTIFICATION_ID</em>, getNotification());<br>                }<br>            }<br><br>            @Override<br>            public void onLocationAvailability(LocationAvailability locationAvailability) {<br>                super.onLocationAvailability(locationAvailability);<br>//                locationAvailability.isLocationAvailable();<br>            }<br>        };<br><br><br>//        create a request for location<br>        createLocationRequest();<br>        getLastLocation();</pre><pre>        mNotificationManager = (NotificationManager) getSystemService(<em>NOTIFICATION_SERVICE</em>);<br><br>    }</pre><p>when ever our app is in foreground and bind the service we need to stop the foreground service.</p><pre>@NonNull<br>@Override<br>public IBinder onBind(Intent intent) {<br>    stopForeground(true);<br>    mChangingConfiguration = false;<br>    return mBinder;<br>}</pre><p>when user returns to the foreground and binds once again with this service. that time onRebind method will get called and the service should stop foreground service when that happens.</p><pre>@Override<br>public void onRebind(Intent intent) {<br>    stopForeground(true);<br>    mChangingConfiguration = false;<br>    super.onRebind(intent);<br>}</pre><p>When our main activity unbind the service that time onUnbind method will get called. This method may called when app configuration changed or when app goes in background. So it is called because of configuration changes then we will not do any thing. If it is the other reason we need to start our foreground service. This method will return true so that ensures onRebind() is called when a client re-binds.</p><pre>@Override<br>public boolean onUnbind(Intent intent) {<br>    Log.<em>i</em>(<em>TAG</em>, &quot;Last client unbound from service&quot;);<br>    if (!mChangingConfiguration) {<br>       startForeground(<em>NOTIFICATION_ID</em>, getNotification());<br>    }<br>    return true; // Ensures onRebind() is called when a client re-binds.<br>}</pre><p>So finally <a href="https://github.com/stAyushJain/LocationUpdates-Android-o/blob/master/app/src/main/java/com/example/keerthiacharya/demolocationupdate/service/LocationUpdatesService.java"><strong>HERE</strong></a> is My Service class.</p><p><strong>The activity class :</strong></p><p>Our activity holds two button for requesting and removing the update.</p><p>on click of request button we will call the requestLocationUpdates of service class that will start service.</p><pre>@Override<br>protected void onCreate(Bundle savedInstanceState) {<br>    super.onCreate(savedInstanceState);<br>    setContentView(R.layout.<em>activity_main</em>);<br><br>    if(!checkPermission())<br>    {<br>        requestPermissions();<br>    }<br>}</pre><p>Now we will create an instance of service class and bind it to activity</p><pre>@Override<br>protected void onResume() {<br>    super.onResume();<br>    if(checkPermission())<br>    {<br>        bindService(new Intent(this, LocationUpdatesService.class), mServiceConection,<br>                Context.<em>BIND_AUTO_CREATE</em>);<br>        LocalBroadcastManager.<em>getInstance</em>(this).registerReceiver(myReceiver,<br>                new IntentFilter(LocationUpdatesService.<em>ACTION_BROADCAST</em>));<br><br>    }<br>}</pre><pre>// ServiceConnection class to get instance of our service<br>private final ServiceConnection mServiceConection = new ServiceConnection() {<br>    @Override<br>    public void onServiceConnected(ComponentName name, IBinder service) {<br>        mLUService = ((LocationUpdatesService.LocationBinder)service).getLocationUpdateService();<br>        mBound = true;<br>    }<br><br>    @Override<br>    public void onServiceDisconnected(ComponentName name) {<br>        mLUService = null;<br>        mBound = false;<br>    }<br>};</pre><p>We had register a receiver. It will helps us to get the updated location form our service class.</p><pre>public class LocationReceiver extends BroadcastReceiver {<br>    @Override<br>    public void onReceive(Context context, Intent intent) {<br>        Location location = intent.getParcelableExtra(LocationUpdatesService.<em>EXTRA_LOCATION</em>);<br>        if (location != null) {<br>            Toast.<em>makeText</em>(context, Utils.<em>getLocationText</em>(location),<br>                    Toast.<em>LENGTH_SHORT</em>).show();<br>        }<br>    }<br><br><br>}</pre><p>Now unregister the receiver and unbind the service class.</p><pre>@Override<br>protected void onPause() {<br>    LocalBroadcastManager.<em>getInstance</em>(this).unregisterReceiver(myReceiver);<br>    super.onPause();<br>}<br><br>@Override<br>protected void onStop() {<br>    if (mBound) {<br>        unbindService(mServiceConection);<br>        mBound = false;<br>    }<br><br>    super.onStop();<br>}</pre><p><a href="https://github.com/stAyushJain/LocationUpdates-Android-o/blob/master/app/src/main/java/com/example/keerthiacharya/demolocationupdate/MainActivity.java"><em>HERE</em></a> is my activity class.</p><p>You can see the entire code <a href="https://github.com/stAyushJain/LocationUpdates-Android-o"><em>HERE</em></a>.</p><h3>Conclusion:</h3><p>These limitations applied to the background service will definitely provide extended battery life and also lower RAM usage. Ultimately it will make your applications smooth and your user happy.</p><p>Thanks for reading this article. Be sure to click ❤ below to recommend this article if you found it helpful. It means a lot to me. Please mention any other possible ways if you think.</p><p>Also, Let’s become friends on <a href="http://linkedin.com/in/ayush-jain1%20Profile%20URL">Linkedin</a>, <a href="https://github.com/stAyushJain">GitHub</a> and <a href="https://www.facebook.com/ayush.jain.754918">Facebook</a>.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=d228a47a5915" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Android Large Bitmaps VS The OOM]]></title>
            <link>https://medium.com/@ayushjain0801/android-large-bitmaps-vs-the-oom-15266461783d?source=rss-8da9b8617d4------2</link>
            <guid isPermaLink="false">https://medium.com/p/15266461783d</guid>
            <category><![CDATA[android]]></category>
            <dc:creator><![CDATA[Ayush Jain]]></dc:creator>
            <pubDate>Thu, 31 Aug 2017 21:18:40 GMT</pubDate>
            <atom:updated>2017-08-31T21:18:40.726Z</atom:updated>
            <content:encoded><![CDATA[<p>Hello guys, In this Article we will see how to get rid of OOM (OutOFMemory) exception from our crashlytics report. As an developer we always wants our application to look beautiful and images are one of the important part of an application. These images make our application beautiful but sometimes while loading image/bitmap in imageView we get an exception i.e. OOM. Android provides limited amount of memory to an application and devices with bigger dpi screens have a higher value of heap limit. So when ever we use to get this error we can simply use <em>android:largeHeap</em> property, mean simply we are asking for some extra RAM for our application and obviously that is not a good approach. We don’t want our application slower and inefficient GC behaviour.</p><p>There are many possible ways you can find and offcourse <a href="https://github.com/bumptech/glide"><em>GLIDE</em></a> and <a href="http://square.github.io/picasso/"><em>PICASSO</em></a><em> </em>are<em> </em>very famous. This post will give an idea how does these library works and what if you don’t want to use them.</p><p><strong><em>So lets starts with code…..</em></strong></p><p>Before setting up bitmap into imageView we can put some restriction,</p><p>1 : Get the bitmap size.</p><p>2 : Check the available memory left</p><p>3 : If bitmap size is bigger then available memory then try to reduce it.</p><p><strong>1 : Get the bitmap size</strong></p><p>Using BitmapFactory.Options we will calculate the size of bitmap. BitmapFactory.<em>decodeResource </em>method<em> </em>will use BitmapFactory.Option instance. Because here we just doing a calculation and don’t want to load bitmap into memory so we will set options.inJustDecodeBounds as true. As you can see in below code we are getting the required size .</p><pre>private void readBitmapInfo() {<br>        final Resources res = getActivity().getResources();<br>        final BitmapFactory.Options options = new BitmapFactory.Options();<br>        options.inJustDecodeBounds = true;<br>        BitmapFactory.<em>decodeResource</em>(res, R.drawable.heavy, options);<br>        float imageHeight = options.outHeight;<br>        float imageWidth = options.outWidth;<br><br>        Log.d(TAG, “bitmap size required: “+imageWidth * imageHeight * 4.0f/1024.0f * 1024.0f + &quot; MB&quot;);<br> }</pre><p>I am using 4.0/1024.0 * 1024.0 to calculate size in MB. each pixel is represented as 32 bits, i.e. 4 bytes.</p><p><strong><em>2 : Check the available memory left :</em></strong></p><p>Using Runtime class in android we can get the provide memory by android and the amount of memory left</p><pre>public static final float <em>BYTES_IN_MB </em>= 1024.0f * 1024.0f;<br><br>    public static float availMemory() {<br>        final Runtime rt = Runtime.<em>getRuntime</em>();<br>         float bytesUsed = rt.totalMemory();<br>         float bytesTotal = rt.maxMemory();<br>//        in MB<br>        bytesTotal = bytesTotal/<em>BYTES_IN_MB</em>;<br>        float mbUsed = bytesUsed/<em>BYTES_IN_MB</em>;<br>        float freeMemoryInMB = bytesAvailable - mbUsed;<br>        return freeMemoryInMB;<br>    }</pre><p>so now we have completed our two steps now we just have to check that our bitmap size should be less than <em>availMemory(). </em>If not then we have to reduce the size of our bitmap.</p><p><strong><em>Reducing Bitmap Size :</em></strong></p><p>To reduce the size of bitmap again we need to use an another property of bitmap.option i.e. inSampleSize. <strong>inSampleSize</strong> is nothing but scaling factor or can say a constant value that will tell bitmap to reduce its height and width factor. Assume we have a bitmap image with resolution 2000x1500 before decoding and we set our inSampleSize value as 5 then after decoding we will have a bitmap image with resolution 400x300.</p><p>Here’s a <a href="https://developer.android.com/topic/performance/graphics/load-bitmap.html#load-bitmap">method</a> to calculate a sample size value that is a <strong>power of two</strong> based on a target width and height :</p><p><strong>Note:</strong> A power of two value is calculated because the decoder uses a final value by rounding down to the nearest power of two, as per the <a href="https://developer.android.com/reference/android/graphics/BitmapFactory.Options.html#inSampleSize">inSampleSize</a> documentation.</p><pre>public static int calculateInSampleSize(<br>            BitmapFactory.Options options, int reqWidth, int reqHeight) {<br>    // Raw height and width of image<br>    final int height = options.outHeight;<br>    final int width = options.outWidth;<br>    int inSampleSize = 1;<br><br>    if (height &gt; reqHeight || width &gt; reqWidth) {<br><br>        final int halfHeight = height / 2;<br>        final int halfWidth = width / 2;<br><br>        // Calculate the largest inSampleSize value that is a power of 2 and keeps both<br>        // height and width larger than the requested height and width.<br>        while ((halfHeight / inSampleSize) &gt;= reqHeight<br>                &amp;&amp; (halfWidth / inSampleSize) &gt;= reqWidth) {<br>            inSampleSize *= 2;<br>        }<br>    }<br><br>    return inSampleSize;<br>}</pre><p>So Now we have inSampleSize so lets decode our bitmap :</p><pre>public static Bitmap decodeSampledBitmapFromResource(Resources res, int resId,<br>        int reqWidth, int reqHeight) {<br><br>    // First decode with inJustDecodeBounds=true to check dimensions<br>    final BitmapFactory.Options options = new BitmapFactory.Options();<br>    options.inJustDecodeBounds = true;<br>    BitmapFactory.decodeResource(res, resId, options);<br><br>    // Calculate inSampleSize</pre><pre>// options.<strong>inSampleSize</strong> = <em>calculateInSampleSize</em>(options, 500,500);</pre><pre>   options.inSampleSize = calculateInSampleSize(options, reqWidth, reqHeight);<br><br>    // Decode bitmap with inSampleSize set<br>    options.inJustDecodeBounds = false;<br>    return BitmapFactory.decodeResource(res, resId, options);<br>}</pre><p>As you can see we are using inJustDecodeBounds two times. set inJustDecodeBounds to true , pass the options through and then decode again using the new calculated inSampleSize. And that’s it now we are done with this and we can set it into imageView.</p><pre>mImageView.setImageBitmap(<br>    decodeSampledBitmapFromResource(getResources(), R.id.myimage, 100, 100));</pre><p>So Now a big question can come &gt;&gt;&gt;&gt;<em> Why would I write that much long code simply can use Glide or Picasso !!</em></p><p>Yes, you can but sometimes we don’t want to use libraries because we don’t have that much use like, may be it’s just a one or two images.</p><p>But this is not the end, <strong>lets talk about performance</strong>. As we all know that Glide and Picasso use a cache mechanism for speed up i.e. LRU Cache.</p><p>On a listView whenever we scroll down/up and again come back to same page then we don’t want to do entire process (reload the image )again and again so we can make a cache that will store our bitmap and whenever any cell/item of list will come in focus first the we will check in cache memory if bitmap is present then directly the decoded bitmap can be used.</p><p>So lets create a cache:</p><pre>class BitMapCache extends LruCache&lt;String, Bitmap&gt; {<br><br>    public BitMapCache(int maxSize) {<br>        super(maxSize);<br>    }<br><br>    @Override<br>    protected int sizeOf(ImagePoolKey key, Bitmap value) {<br>        int kbOfBitmap = value.getByteCount() / 1024;<br>        return kbOfBitmap;<br>    }<br>}</pre><p>And Now first we will check in cache</p><pre>private BitMapCache cache;</pre><pre>@Override<br>protected void onCreate(Bundle savedInstanceState) {<br>  ActivityManager actManager = (ActivityManager) getSystemService(<br>            Context.ACTIVITY_SERVICE);<br>        int maxKb = actManager.getMemoryClass() * 1024;<br>        int limitInKb = maxKb / 8;<br>        cache = new BitMapCache(limitInKb);<br>..<br>..<br>..<br>..</pre><pre>}</pre><pre>public void display(String position, Bitmap bitmap) {<br>        Bitmap image = cache.get(position);<br>        if (image != null) {<br>            imageview.setImageBitmap(image);<br>        }<br>        else {<br>// set image for the first time</pre><pre>           decodeSampledBitmapFromResource(getResources(), R.id.myimage, 100, 100));<br>        }<br>    }</pre><p>Now every time our bitmap will be check in cache memory.</p><p>If system is running low on memory and your process is near the beginning of the LRU list. Although your app process is not at a high risk of being killed, the system may already be killing processes in the LRU list, so you should release resources that are easy to recover so your process will remain in the list and resume quickly when the user returns to your app. <a href="https://stackoverflow.com/questions/19398827/understanding-ontrimmemory-int-level"><strong><em>source</em></strong></a></p><pre>@Override<br>    public void onTrimMemory(int level) {<br>        if (level &gt;= TRIM_MEMORY_MODERATE) {<br>            cache.evictAll();<br>        }<br>        else if (level &gt;= TRIM_MEMORY_BACKGROUND) {<br>            cache.trimToSize(cache.size() / 2);<br>        }<br>    }</pre><p>Thanks for reading this article. Be sure to click ❤ below to recommend this article if you found it helpful. It means a lot to me. Please mention any other possible ways if you think.</p><p>Also, Let’s become friends on <a href="http://linkedin.com/in/ayush-jain1%20Profile%20URL">Linkedin</a>, <a href="https://github.com/stAyushJain">GitHub</a> and <a href="https://www.facebook.com/ayush.jain.754918">Facebook</a>.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=15266461783d" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Android Design Pattern]]></title>
            <link>https://medium.com/@ayushjain0801/android-design-pattern-9c2933262030?source=rss-8da9b8617d4------2</link>
            <guid isPermaLink="false">https://medium.com/p/9c2933262030</guid>
            <category><![CDATA[android]]></category>
            <dc:creator><![CDATA[Ayush Jain]]></dc:creator>
            <pubDate>Mon, 28 Aug 2017 12:07:09 GMT</pubDate>
            <atom:updated>2017-08-28T18:53:21.614Z</atom:updated>
            <content:encoded><![CDATA[<p>As an android developer you should know these design pattern :</p><p>1 : <strong>Singleton class</strong> -&gt; <a href="https://android.jlelse.eu/how-to-make-the-perfect-singleton-de6b951dfdb0">HERE</a> you will get the best idea.</p><p>2 : <strong>Factory</strong> -&gt; <a href="https://www.javatpoint.com/factory-method-design-pattern">HERE</a> you will get an idea of that.</p><p>3 : <strong>Iterator</strong> -&gt; <a href="https://dzone.com/articles/design-patterns-iterator">THIS</a> link explained it very well.</p><p>4 : <strong>Builder</strong> -&gt; <a href="http://www.vogella.com/tutorials/DesignPatternBuilder/article.html">HERE</a> you will find a good explanation about builder pattern in java8.</p><p>5 : <strong>Dependency injection</strong> -&gt; No doubt <a href="https://google.github.io/dagger/">Dagger2</a> is best for it. if you already using it just check it out for new version of Dagger <a href="https://medium.com/@iammert/new-android-injector-with-dagger-2-part-1-8baa60152abe">HERE</a></p><p>6 : <strong>Custom Listeners</strong> -&gt; We generally use onClickListeners on button click or locationUpdateListeners so how can we our own listeners, check it out <a href="https://guides.codepath.com/android/Creating-Custom-Listeners">HERE</a></p><p>7 : <strong>Adapter</strong> -&gt; Adapter is an interface which is responsible for the communication between the adapterView and the data we want to display generally we use it for displaying data in listView/recyclerView or exposing data from cursor ( pointed to a row to the result set returned by a database query and also provides access to modify the data )to our list. <a href="https://developer.android.com/reference/android/widget/Adapter.html">HERE</a> you will find a brief explanation.</p><p>Thanks for reading this article. Be sure to click ❤ below to recommend this article if you found it helpful. It means a lot to me. Please mention any other possible ways if you think.</p><p>Also, Let’s become friends on <a href="http://linkedin.com/in/ayush-jain1%20Profile%20URL">Linkedin</a>, <a href="https://github.com/stAyushJain">GitHub</a> and <a href="http://facebook.com/ayush.jain.754918">Facebook</a>.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=9c2933262030" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Android Component and Service Talk]]></title>
            <link>https://medium.com/@ayushjain0801/android-component-and-service-talk-6657002fdff8?source=rss-8da9b8617d4------2</link>
            <guid isPermaLink="false">https://medium.com/p/6657002fdff8</guid>
            <category><![CDATA[android]]></category>
            <dc:creator><![CDATA[Ayush Jain]]></dc:creator>
            <pubDate>Sun, 27 Aug 2017 19:53:22 GMT</pubDate>
            <atom:updated>2017-08-27T19:53:22.912Z</atom:updated>
            <content:encoded><![CDATA[<p>This article will give you an idea which can be used for communication between an activity/fragment and a service class. You can find lots of article on this topic but I’ll try to give an idea of all possible ways. Ok so enough talk let me start with it.</p><h3>Bus architecture :</h3><p>You can use <a href="https://github.com/greenrobot/EventBus">EventBus</a> from greenrobot.</p><h3>Using Broadcast Receivers :</h3><p>Assume we have an Intent service and we want to pass our data to activity then we can use broadcast receivers for communication. Your Service class will look like this:</p><pre>public class TestIntentService extends IntentService {<br>    public TestIntentService() {<br>        super(&quot;TestIntentService&quot;);<br>    }</pre><pre>    @Override<br>    protected void onHandleIntent(@Nullable Intent intent) {<br></pre><pre><em>//      doSomeWork()</em><br>        ..<br>        ..<br>﻿ <br>        Intent senderIntent = new Intent();<br>        senderIntent.setAction(ServiceReceivers.SERVICE_ACTION);<br>        senderIntent.putExtra(&quot;data&quot;,&quot;result&quot;);<br>        senderIntent.addCategory(Intent.CATEGORY_DEFAULT);<br>        sendBroadcast(senderIntent);<br>    }<br>}</pre><p>Broadcast Receiver class will look like this :</p><pre>public class ServiceReceivers extends BroadcastReceiver {</pre><pre>    public final static String SERVICE_ACTION = &quot;com.example.keerthiacharya.androidjob.receivers&quot;;<br>    @Override<br>    public void onReceive(Context context, Intent intent) {<br>        Log.d(&quot;onReceive&quot;, &quot;onReceive: &quot;+intent.getExtras().getString(&quot;data&quot;));<br>    }<br>}</pre><p>and inside main activity register receiver</p><pre><em>// write this code inside onCreate()</em><br>serviceReceivers = new ServiceReceivers();<br>IntentFilter intentFilter = new IntentFilter(ServiceReceivers.SERVICE_ACTION);<br>intentFilter.addCategory(Intent.CATEGORY_DEFAULT);<br>registerReceiver(serviceReceivers,intentFilter);</pre><pre>..<br>..<br>..</pre><pre><em>// make sure to unRegister it on pause</em></pre><pre>@Override<br>protected void onPause() {<br>    super.onPause();<br>    unregisterReceiver(serviceReceivers);<br>}</pre><p><strong>Using RegisterReceiver</strong></p><p>Generic interface for receiving a callback result from someone. Use this by creating a subclass and implement onReceiveResult.</p><pre>public class CustomReceiver extends ResultReceiver {</pre><pre>    public static final String RESULT_RECEIEVER_EXTRA = &quot;receiver&quot;;<br>    private Receiver mReceiver;<br>    public CustomeReceiver(Handler handler) {<br>        super(handler);<br>    }</pre><pre>    @Override<br>    protected void onReceiveResult(int resultCode, Bundle resultData) {<br>        if (mReceiver != null) {<br>            mReceiver.onReceiveResult(resultCode, resultData);<br>        }</pre><pre>    }</pre><pre><em>// using this interface for transfer data to activity/fragment</em><br>    public interface Receiver {<br>        public void onReceiveResult(int resultCode, Bundle resultData);</pre><pre>    }</pre><pre>    public void setReceiver(Receiver receiver) {<br>        mReceiver = receiver;<br>    }</pre><pre>}</pre><p>then inside a service class you can use put this code. I am using IntentService so my code will look like this:</p><pre>@Override<br>    protected void onHandleIntent(@Nullable Intent intent) {<br><em>//      if using customeReceiver</em><br>if(intent !=null) {<br><em>// Here will get here ResultReceiver object not  our Custom Receiver class instance</em><br>    ResultReceiver receiver = intent.getParcelableExtra(CustomeReceiver.RESULT_RECEIEVER_EXTRA);<br><em>//        now create a Bundle and put data on that</em><br>    Bundle bundle = new Bundle();<br>    bundle.putString(&quot;data&quot;, &quot;data&quot;);<br>    receiver.send(1,bundle);</pre><pre>    <br>}</pre><p>and finally our MainActivity will look like</p><pre>public class MainActivity extends AppCompatActivity implements CustomeReceiver.Receiver{</pre><pre>    public CustomeReceiver customeReceiver;</pre><pre>    @Override<br>    protected void onCreate(Bundle savedInstanceState) {<br>        super.onCreate(savedInstanceState);<br>        setContentView(R.layout.activity_main);</pre><pre><em>//        using ResultReceiver class</em><br>        customeReceiver = new CustomeReceiver(new Handler());<br>        customeReceiver.setReceiver(this);</pre><pre>        Intent serviceIntent = new Intent(this, TestIntentService.class);<br>        serviceIntent.putExtra(CustomeReceiver.RESULT_RECEIEVER_EXTRA, customeReceiver);<br>        startService(serviceIntent);<br>    }</pre><pre>   @Override<br>   public void onReceiveResult(int resultCode, Bundle resultData) {<br>      Log.d(&quot;onReceive&quot;, &quot;gotcha  &quot;+resultData.getString(&quot;data&quot;));<br>   }</pre><p><strong>Using ServiceConnection class</strong></p><p>Using serviceConnection class we can get bound service class object. Our bound service and application are running in same process. So first we have to create an IBinder object that we will use for sending data from activity to bound service class. For creating an IBinder object we need to create a class that will extend Binder class.</p><pre>public class TestBoundService extends Service {<br>    private final IBinder mBinder = new MyBinder();</pre><pre>    @Nullable<br>    @Override<br>    public IBinder onBind(Intent intent) {<br>        return mBinder;<br>    }</pre><pre>    public class MyBinder extends Binder {<br>         public TestBoundService getBindedService()<br>        {<br>            return TestBoundService.this;<br>        }<br>    }</pre><pre>    @Override<br>    public void onCreate() {<br>      .....<br>    }</pre><pre>    @Override<br>    public void onDestroy() {<br>     .....<br>    }</pre><pre>}</pre><p>Now inside MainActivity we will use ServiceConnection class, Interface for monitoring the state of an application service. This class have three methods and they will call on main thread.</p><p>onServiceConnected(ComponentName name, IBinder service) : Called when a connection to the Service has been established, with the IBinder of the communication channel to the Service.</p><p>onServiceDisconnected(ComponentName name) Called when a connection to the Service has been lost.</p><p>So now inside MainActivity we will call this :</p><pre>private TestBoundService mBoundService;<br>    private boolean boundStatus;</pre><pre>    private ServiceConnection mConnection = new ServiceConnection() {<br>        public void onServiceConnected(ComponentName className, IBinder service) {<br>            <em>//  connection with the service has been established</em><br>            mBoundService = ((TestBoundService.MyBinder)service).getBindedService();</pre><pre><em>//            now we have mBoundService( our service object ) we can use it if we want to pass any data</em></pre><pre>        }</pre><pre>        public void onServiceDisconnected(ComponentName className) {<br>            <em>// connection with the service has been unexpectedly disconnected</em></pre><pre>            <em>//           make it available for GC</em><br>            mBoundService = null;</pre><pre>        }<br>    };</pre><p>source for this activity <a href="https://android.googlesource.com/platform/development/+/master/samples/ApiDemos/src/com/example/android/apis/app/LocalServiceActivities.java">HERE</a></p><p>Thanks for reading this article. Be sure to click ❤ below to recommend this article if you found it helpful. It means a lot to me. Please mention any other possible ways if you think.</p><p>Also, Let’s become friends on <a href="http://linkedin.com/in/ayush-jain1%20Profile%20URL">Linkedin</a>, <a href="https://github.com/stAyushJain">GitHub</a> and <a href="https://www.facebook.com/ayush.jain.754918">Facebook</a>.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=6657002fdff8" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>