Monday, September 21, 2020

Static content in screen bottom coming over the recyclerview

Bottomsheet in activity covering over the recyclerview content. 

After little search and different ways to fix it found workarround to tackle this. 

as follow. 


<android.support.v7.widget.RecyclerView
...
android:clipToPadding="false"
android:paddingBottom="72dp"
/>

Saturday, August 1, 2020

Memory leak in startactivityforresult

If we have to start Activity B in Activity A for result as follow 

We will call startActivityForResult from Activity A we will set some result in out activity B and return result.
But what if user presses back button on Activity B how should we handle this case.

I was running LeakCanary and found surprising result that it was always leaking my Activity B. reason is that it wasn't finishing and staying in memory even after returning to Activity B with Back Press.

So here is the solution that I found to resolve this. So quick fix is call method finishActivity with request code that you have passed while calling activity B. 

class ActivityA: AppCompatActivity(){

    private val requestCode = 1001

    fun startActivityB(){
    startActivityForResult(Intent(this, ActivityB::class.java).apply 
                {
                    putExtra("category_id", currentCategory._id)
                    putExtra("category_color", currentCategory.color)
                    putExtra("category_name", currentCategory.name)

                }, requestCode)
    }

    override fun onActivityReenter(resultCode: Int, data: Intent?) {
        super.onActivityReenter(resultCode, data)
        finishActivity(requestCode)
    }

}

Saturday, June 6, 2020

RxAndroid basic example

RxAndroid is flavour of reactive programming implementation for Android.

Base of reactive programming is Observer design pattern.

Let's understand Observer design pattern first.

Observer Design Pattern:
Observer design pattern is one of the behavioural design pattern. It's about communication between objects. In observer design pattern main object emits the change in it and all the object s who are observing to change in main object gets notification about it.