<?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 Rahulmani on Medium]]></title>
        <description><![CDATA[Stories by Rahulmani on Medium]]></description>
        <link>https://medium.com/@rahulmani610?source=rss-3c6a47c77ce------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/0*VPoa2jdSc4JMCazU</url>
            <title>Stories by Rahulmani on Medium</title>
            <link>https://medium.com/@rahulmani610?source=rss-3c6a47c77ce------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Wed, 18 Nov 2026 06:34:06 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@rahulmani610/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[Why I Am Choosing DataStore Instead of SharedPreferences — Let Me Make It Clear…]]></title>
            <link>https://rahulmani610.medium.com/why-i-am-choosing-datastore-instead-of-sharedpreferences-let-me-make-it-clear-a021783773b9?source=rss-3c6a47c77ce------2</link>
            <guid isPermaLink="false">https://medium.com/p/a021783773b9</guid>
            <dc:creator><![CDATA[Rahulmani]]></dc:creator>
            <pubDate>Fri, 25 Jul 2025 13:48:09 GMT</pubDate>
            <atom:updated>2025-07-25T13:48:09.493Z</atom:updated>
            <content:encoded><![CDATA[<h3>Why I Am Choosing DataStore Instead of SharedPreferences — Let Me Make It Clear…</h3><p>As an Android developer, before Jetpack Compose came into play, we used <strong>SharedPreferences</strong> to store a small amount of data locally. SharedPreferences was good — simple, quick, and easy to implement.</p><p>But just like in life <strong>as human beings, new things come, and old ones fade away 😉 -</strong>the same applies to Android development.</p><p>Key reasons why I’m choosing DataStore (based on the Reactive Programming Model):</p><ol><li><strong>Asynchronous by default</strong> — prevents main thread blocking.</li><li>Ensures a <strong>smoother user experience</strong>.</li><li>Reduces runtime <strong>Errors</strong></li><li>Ensures <strong>type safety</strong> and reduces chances of key mismatches</li><li>Error handling during data <strong>Read</strong> and <strong>Write</strong></li><li>Supports <strong>Protocol Buffers</strong> for storing structured and <strong>complex data</strong></li></ol><p>I’ll keep it simple. As a developer, I choose DataStore because it’s easier to use, works better than SharedPreferences, and just makes my work smoother. 😊</p><p>Let’s Dive Into the <strong>Types</strong> <strong>of</strong> <strong>DataStore</strong> 🙌</p><p>DataStore has <strong>two types</strong>, and you can use them based on what kind of data you want to save</p><ol><li><strong>Preferences DataStore</strong></li><li><strong>Proto DataStore</strong></li></ol><p><strong>👉 Preferences DataStore :</strong></p><ol><li>It stores data like <strong>SharedPreference</strong> using <strong>keys</strong> and <strong>values </strong>😕</li><li>DataStore is <strong>faster</strong>, <strong>safer</strong>, and more <strong>efficient</strong> than SharedPreferences — sorry 😅</li><li><strong>Better for sensitive data:</strong> DataStore supports encryption, so it’s safer for storing private information 🔐</li><li>Type-safe: avoids key mismatches 🙌</li></ol><p>👉 <strong>Proto DataStore :</strong></p><ol><li>Good for <strong>complex or structured data</strong></li><li><strong>Type-safe</strong>: no need to manage keys manually</li><li><strong>Fast and efficient</strong>, especially with large data</li><li><strong>Ready for future sync use-cases</strong>: Proto data is easier to serialize and deserialize across network layers or even backup/restore operations.</li></ol><p><strong>And that’s why I’ve officially broken up with SharedPreferences 💔📦</strong><br> <strong>DataStore is my new bestie — smooth, reliable, and coroutine-friendly 😎</strong><br> Still using SharedPreferences? Time to upgrade — your future self (and your app) will high-five you later ✋😄</p><p>#Android #Kotlin #JetpackCompose #DataStore #AndroidDevelopment #SharedPreferences</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=a021783773b9" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[How to Fetch The Data In RecyclerView Using Kotlin For Beginners]]></title>
            <link>https://rahulmani610.medium.com/how-to-fitch-the-data-in-recycler-view-using-kotlin-8df626af73e2?source=rss-3c6a47c77ce------2</link>
            <guid isPermaLink="false">https://medium.com/p/8df626af73e2</guid>
            <dc:creator><![CDATA[Rahulmani]]></dc:creator>
            <pubDate>Mon, 28 Jun 2021 09:18:53 GMT</pubDate>
            <atom:updated>2021-06-29T13:22:39.101Z</atom:updated>
            <content:encoded><![CDATA[<p><strong>How to Fetch The Data In RecyclerView Using Kotlin For Beginners</strong></p><p>Here I Create a Recycler View to Bind the list of Product</p><p><strong>What is RecyclerView?</strong></p><p>RecyclerView is a container used for <strong>displaying a large number of data</strong> sets that can be scrolled very efficiently by maintaining a limited number of view</p><p>Recycler view need Adapter class and have three override methods are as follows</p><ul><li>onCreateViewHolder(ViewGroup parent, int viewType)</li><li>onBindViewHolder(RecyclerView.ViewHolder holder, int position)</li><li>get item count()</li></ul><p><strong>onCreateViewHolder(ViewGroup, int)</strong></p><p>This method is called when the adapter is created and is used to initialize your ViewHolder(s).</p><p><strong>onBindViewHolder(RecyclerView.ViewHolder, int)</strong></p><p>onBindViewHolder deals with the setting of different data and methods related to clicks on particular items of the RecyclerView.</p><p><strong>getItemCount()</strong></p><p>This overridden method returns the size of the collection that contains the items we want to display</p><p>Without any further delay, Let’s get into the <strong>Android studio</strong></p><ol><li>Create the project</li><li>Add the recycler view to the Activity</li><li>Create another <strong>XML(</strong>Activity<strong>) </strong>for recycler view showing product details</li><li>Create a Model/class</li><li>Create an Adapter class to bind the product detail to the Recycler view</li><li>Connect to the RecyclerView to Adapter class</li></ol><p><strong>1.Create Project</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/900/1*M1YU21LuD8A-0pLpBazmpw.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/900/1*_PU6UrTDwSA79yQEFICpwQ.png" /></figure><p><strong>2.Add the recycler view to the Activity</strong></p><p>Go to the <strong>activity_main.xml </strong>layout and add a Recycler view, It should be inside the parent layout.</p><p>Now your activity_main should look like this</p><pre>&lt;RelativeLayout<br>    xmlns:android=&quot;http://schemas.android.com/apk/res/android&quot;<br>    android:layout_width=&quot;match_parent&quot;<br>    android:layout_height=&quot;match_parent&quot;<br>    android:padding=&quot;16dp&quot;<br>    android:id=&quot;@+id/relativeCart&quot;&gt;<br><br><br>    &lt;androidx.recyclerview.widget.RecyclerView<br>        android:id=&quot;@+id/recyclerViewCart&quot;<br>        android:layout_width=&quot;match_parent&quot;<br>        android:layout_height=&quot;match_parent&quot;<br>        android:layout_above=&quot;@+id/paymentDetails&quot;<br>        /&gt;<br>   &lt;/RelativeLayout&gt;</pre><p><strong>3. Create another XML(Activity) for recycler view showing product detail</strong></p><p>Create a new layout file called <strong>productdetails.xml, </strong>it will bind the data in RecyclerView</p><pre>&lt;?xml version=&quot;1.0&quot; encoding=&quot;utf-8&quot;?&gt;<br>&lt;androidx.cardview.widget.CardView<br>    xmlns:android=&quot;http://schemas.android.com/apk/res/android&quot;<br>    xmlns:app=&quot;http://schemas.android.com/apk/res-auto&quot;<br>    android:layout_width=&quot;match_parent&quot;<br>    android:layout_height=&quot;wrap_content&quot;<br>    android:layout_marginTop=&quot;8dp&quot;<br>    android:layout_marginEnd=&quot;8dp&quot;<br>    android:layout_marginStart=&quot;8dp&quot;<br>    android:layout_marginBottom=&quot;16dp&quot;<br>    app:cardCornerRadius=&quot;8dp&quot;<br>    app:cardElevation=&quot;8dp&quot;<br>    app:cardBackgroundColor=&quot;@color/white&quot;&gt;<br><br><br>    &lt;LinearLayout<br>        android:layout_width=&quot;match_parent&quot;<br>        android:layout_height=&quot;wrap_content&quot;<br>        android:orientation=&quot;horizontal&quot;<br>        android:id=&quot;@+id/layout1&quot;<br>        android:padding=&quot;2dp&quot;&gt;<br><br><br>        &lt;ImageView<br>            android:id=&quot;@+id/foodImage_id&quot;<br>            android:layout_width=&quot;90dp&quot;<br>            android:padding=&quot;5dp&quot;<br>            android:layout_height=&quot;100dp&quot; /&gt;<br><br>        &lt;LinearLayout<br>            android:id=&quot;@+id/layoutInner&quot;<br>            android:layout_width=&quot;149dp&quot;<br>            android:layout_height=&quot;wrap_content&quot;<br>            android:layout_gravity=&quot;center&quot;<br>            android:layout_marginLeft=&quot;16dp&quot;<br>            android:layout_weight=&quot;1&quot;<br>            android:orientation=&quot;vertical&quot;&gt;<br><br><br>            &lt;TextView<br>                android:id=&quot;@+id/product_name_id&quot;<br>                android:layout_width=&quot;match_parent&quot;<br>                android:layout_height=&quot;wrap_content&quot;<br>                android:hint=&quot;Product Name&quot;<br>                android:textColor=&quot;@color/black&quot;<br>                android:textSize=&quot;18sp&quot;<br>                android:textStyle=&quot;bold&quot; /&gt;</pre><pre>            &lt;LinearLayout<br>                android:layout_width=&quot;wrap_content&quot;<br>                android:layout_height=&quot;wrap_content&quot;<br>                android:gravity=&quot;bottom&quot;<br>                android:orientation=&quot;horizontal&quot;&gt;<br><br>                &lt;TextView<br>                    android:id=&quot;@+id/actual_price&quot;<br>                    android:layout_width=&quot;wrap_content&quot;<br>                    android:layout_height=&quot;wrap_content&quot;<br>                    android:hint=&quot;Actual Price&quot;<br>                    android:textColor=&quot;@color/black&quot;<br>                    android:textSize=&quot;12sp&quot; /&gt;<br><br>                &lt;TextView<br>                    android:id=&quot;@+id/price_id&quot;<br>                    android:layout_width=&quot;wrap_content&quot;<br>                    android:layout_height=&quot;wrap_content&quot;<br>                    android:text=&quot;=10&quot;<br>                    android:textColor=&quot;@color/black&quot;<br>                    android:textSize=&quot;12sp&quot; /&gt;<br><br>            &lt;/LinearLayout&gt;<br><br>            &lt;LinearLayout<br>                android:layout_width=&quot;wrap_content&quot;<br>                android:layout_height=&quot;wrap_content&quot;<br>                android:gravity=&quot;bottom&quot;<br>                android:orientation=&quot;horizontal&quot;&gt;<br><br>                &lt;TextView<br>                    android:id=&quot;@+id/offer&quot;<br>                    android:layout_width=&quot;wrap_content&quot;<br>                    android:layout_height=&quot;wrap_content&quot;<br>                    android:text=&quot;offer = &quot;<br>                    android:textColor=&quot;@color/black&quot;<br>                    android:textSize=&quot;12sp&quot; /&gt;<br>                &lt;TextView<br>                    android:id=&quot;@+id/offer_id&quot;<br>                    android:layout_width=&quot;wrap_content&quot;<br>                    android:layout_height=&quot;wrap_content&quot;<br>                    android:text=&quot;10&quot;<br>                    android:textColor=&quot;@color/black&quot;<br>                    android:textSize=&quot;12sp&quot; /&gt;<br>            &lt;/LinearLayout&gt;<br>        &lt;/LinearLayout&gt;<br><br>        &lt;LinearLayout<br>            android:layout_width=&quot;wrap_content&quot;<br>            android:layout_height=&quot;wrap_content&quot;<br>            android:orientation=&quot;vertical&quot;<br>            android:layout_gravity=&quot;center&quot;&gt;<br>            &lt;LinearLayout<br>                android:layout_width=&quot;120dp&quot;<br>                android:layout_height=&quot;wrap_content&quot;<br>                android:orientation=&quot;horizontal&quot;<br>                android:gravity=&quot;center&quot;&gt;<br>                &lt;Button<br>                    android:id=&quot;@+id/decrease&quot;<br>                    android:layout_width=&quot;30dp&quot;<br>                    android:layout_height=&quot;30dp&quot;<br>                    android:text=&quot;-&quot;<br>                    android:background=&quot;@color/black&quot;<br>                    android:textColor=&quot;@color/white&quot;<br>                    android:textSize=&quot;25sp&quot;<br>                    android:textStyle=&quot;bold&quot;/&gt;<br>                &lt;TextView<br>                    android:id=&quot;@+id/integer_number&quot;<br>                    android:layout_width=&quot;30dp&quot;<br>                    android:layout_height=&quot;30dp&quot;<br>                    android:gravity=&quot;center&quot;<br>                    android:text=&quot;0&quot;<br>                    android:textSize=&quot;20sp&quot;<br>                    /&gt;<br>                &lt;Button<br>                    android:id=&quot;@+id/increase&quot;<br>                    android:layout_width=&quot;30dp&quot;<br>                    android:layout_height=&quot;30dp&quot;<br>                    android:text=&quot;+&quot;<br>                    android:textSize=&quot;18sp&quot;<br>                    android:background=&quot;@color/black&quot;<br>                    android:textColor=&quot;@color/white&quot;<br>                    /&gt;<br>            &lt;/LinearLayout&gt;<br>        &lt;/LinearLayout&gt;<br>    &lt;/LinearLayout&gt;<br>&lt;/androidx.cardview.widget.CardView&gt;</pre><p>This will be the template of the Recycler view</p><p><strong>4.Create a Model/class</strong></p><pre>class ProductDetail : Serializable {<br>    var productName: String? = null<br>    var productId: String? = null<br>    var image: String? = null<br>    var price: Int? = null<br>    var offerPrice: Int? = null<br>    var count = 0<br>    var isActive = false<br>}</pre><p>Create a model class that looks like this</p><p><strong>Properties of POJO or MODEL</strong></p><ol><li>All properties must be a public setter and getter methods</li><li>All instance variables should be private</li><li>Should not Extend prespecified classes.</li><li>Should not Implement prespecified interfaces.</li><li>Should not contain prespecified annotations.</li><li>It may not have any argument constructors</li></ol><p><strong>5. Create an Adapter class to bind the product detail to the Recycler view</strong></p><pre>class CartAdapter( val crtInterface: CrtInterface, var details: ArrayList&lt;ProductDetail&gt;) : RecyclerView.Adapter&lt;CartAdapter.MyViewHolder?&gt;() {<br>     interface CrtInterface {<br>         fun increaseCost(info: ProductDetail?)<br>         fun decreaseCost(info: ProductDetail?)<br>     }<br>    override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): MyViewHolder {<br>        val inflater: LayoutInflater = LayoutInflater.from(parent.<em>context</em>)<br>        val view: View = inflater.inflate(R.layout.<em>productdetails</em>, parent, false)<br>        return MyViewHolder(view)<br>    }<br><br>    override fun onBindViewHolder(holder: MyViewHolder, position: Int) {<br>        val Current: ProductDetail = details[position]<br>        if (Current != null) {<br>            holder.productName.setText(Current.productName)<br>            holder.price.setText(Current.price.<em>toString</em>() + &quot;&quot;)<br>            holder.offerPrice.setText(Current.offerPrice.<em>toString</em>() + &quot;&quot;)<br>            Picasso.get().load(Current.image).into(holder.imageView)<br>            holder.quantity.setText(Current.count.toString()+ &quot;&quot;)<br>            holder.Increment.setOnClickListener <strong>{ </strong>crtInterface.increaseCost(Current) <strong>}<br>            </strong>holder.Decrement.setOnClickListener <strong>{ </strong>crtInterface.decreaseCost(Current) <strong>}<br><br>        </strong>}<br>    }<br><br>    override fun getItemCount():<br>        Int = details.size<br><br>    inner class MyViewHolder(itemView: View) : RecyclerView.ViewHolder(itemView) {<br>        var productName: TextView<br>        var productId: TextView? = null<br>        var price: TextView<br>        var offerPrice: TextView<br>        var quantity: TextView<br>        var imageView: ImageView<br>        var Increment: Button<br>        var Decrement: Button<br>        lateinit var addCart: Button<br><br>        init {<br>            productName = itemView.findViewById&lt;TextView&gt;(R.id.<em>product_name_id</em>)<br>            price = itemView.findViewById&lt;TextView&gt;(R.id.<em>price_id</em>)<br>            offerPrice = itemView.findViewById&lt;TextView&gt;(R.id.<em>offer_id</em>)<br>            imageView = itemView.findViewById(R.id.<em>foodImage_id</em>)<br>            quantity = itemView.findViewById&lt;TextView&gt;(R.id.<em>integer_number</em>)<br>            Increment = itemView.findViewById(R.id.<em>increase</em>)<br>            Decrement = itemView.findViewById(R.id.<em>decrease</em>)<br>        }<br>    }<br>}</pre><p><strong>6. Connect to the Recycler view to Adapter class</strong></p><pre>class CartActivity : BaseActivity(), Serializable, CartAdapter.CrtInterface {<br>    var proceed: Button? = null<br>    var dialog: Dialog? = null<br>    var recyclerView: RecyclerView? = null<br>    var cartAdapter: CartAdapter? = null<br>      var cartDetailsList: ArrayList&lt;ProductDetail&gt;? = null<br><br>    override fun getViewModel(): ILifecycle.ViewModel? {<br>       return null<br>    }<br><br>    override fun onCreate(savedInstanceState: Bundle?) {<br>        super.onCreate(savedInstanceState)<br>        setContentView(R.layout.<em>activity_cart</em>)<br>        adjustFontScale(getResources().getConfiguration(), 1.0f)<br>        recyclerView = findViewById&lt;RecyclerView&gt;(R.id.<em>recyclerViewCart</em>)<br>        proceed = findViewById&lt;Button&gt;(R.id.<em>paymentcart</em>)<br>        dialog = Dialog(this)<br>        proceed!!.setOnClickListener <strong>{<br>            </strong>dialog!!.setContentView(R.layout.<em>progressbar</em>)<br>            dialog!!.<em>window</em>!!.setBackgroundDrawable(ColorDrawable(Color.<em>TRANSPARENT</em>))<br>            dialog!!.show()<br>        <strong>}<br>        </strong>val b: Bundle? = getIntent().getExtras()<br>        if (b != null) {<br>            cartDetailsList = b.getSerializable(&quot;cartDetail&quot;) as ArrayList&lt;ProductDetail&gt;?<br>        } else if (b == null) {<br>            Toast.makeText(this, &quot;Cartis empty&quot;, Toast.<em>LENGTH_SHORT</em>).show()<br>        }<br>        amountUpdate(cartDetailsList)<br>        if (cartDetailsList != null) {<br>            cartAdapter = CartAdapter(this@CartActivity,cartDetailsList!!)<br>            recyclerView!!.setHasFixedSize(true)<br>            recyclerView!!.setLayoutManager(LinearLayoutManager(this@CartActivity))<br>            recyclerView!!.setAdapter(cartAdapter)<br>            cartAdapter!!.notifyDataSetChanged()<br>        } else {<br>            Toast.makeText(this, &quot;cart details not available&quot;, Toast.<em>LENGTH_SHORT</em>).show()<br>        }<br>    }</pre><p>the final result looks like this</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/720/1*bdufiU8SnrzHO2WOIvUi_w.jpeg" /></figure><p>Done!!!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=8df626af73e2" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>