Coder Social home page Coder Social logo

hossain-khan / android-recyclerview-onclick-listener Goto Github PK

View Code? Open in Web Editor NEW
0.0 1.0 0.0 542 KB

This is a sample research project that consolidates how RecyclerView item click listener is added using best practices followed in the industry and community.

License: Apache License 2.0

Kotlin 74.04% CSS 13.55% HTML 12.42%
android-recyclerview android-sample-application recyclerview recyclerview-adapter

android-recyclerview-onclick-listener's Introduction

Android RecyclerView Click Listener - Research

This is a sample research project that consolidates how RecyclerView item click listener is added using best practices followed in the industry and community.

project-banner-for-click

Background

Personally, I have been relying on Googling, StackOverflow, and Google's official Android developer guide to implementing click listener for RecyclerView for some time now. Even though, I have settled on the solution recommended by Google, I still wanted to explore the past and present (as of 2020) on what is current and what are the confusions.

Whenever I Googled, I could see I am not the only one looking for answers 🤷, so I decided to dig deeper and document some of the current recommendations from Google from different sources.

Objective

List some historical implementation, as well as current recommended best practice on how to set item click listener on RecyclerView.

NOTE: This is relatively new repository. Once I am finished with research I will try to write an article summarizing my findings 🕵️

Early Sneakpeack

Here is preview of app with different experiment topic and some Synopsis about each way of implementation.

Quick Preview of App

License

See LICENSE.

Copyright 2020 Hossain Khan
Apache License Version 2.0

android-recyclerview-onclick-listener's People

Contributors

hossain-khan avatar

Watchers

 avatar

android-recyclerview-onclick-listener's Issues

Memory leak on RecyclerView adapter

Look into it. Only happened in emulator.

┬───
│ GC Root: System class
│
├─ android.app.ActivityThread class
│    Leaking: NO (MainActivity↓ is not leaking and a class is never leaking)
│    ↓ static ActivityThread.sCurrentActivityThread
├─ android.app.ActivityThread instance
│    Leaking: NO (MainActivity↓ is not leaking)
│    ↓ ActivityThread.mActivities
├─ android.util.ArrayMap instance
│    Leaking: NO (MainActivity↓ is not leaking)
│    ↓ ArrayMap.mArray
├─ java.lang.Object[] array
│    Leaking: NO (MainActivity↓ is not leaking)
│    ↓ Object[].[1]
├─ android.app.ActivityThread$ActivityClientRecord instance
│    Leaking: NO (MainActivity↓ is not leaking)
│    ↓ ActivityThread$ActivityClientRecord.activity
├─ dev.hossain.android.research.MainActivity instance
│    Leaking: NO (NavHostFragment↓ is not leaking and Activity#mDestroyed is false)
│    ↓ MainActivity.navController
├─ androidx.navigation.NavHostController instance
│    Leaking: NO (NavHostFragment↓ is not leaking)
│    ↓ NavHostController.mLifecycleOwner
├─ androidx.navigation.fragment.NavHostFragment instance
│    Leaking: NO (TopicFragment↓ is not leaking and Fragment#mFragmentManager is not null)
│    ↓ NavHostFragment.mChildFragmentManager
├─ androidx.fragment.app.FragmentManagerImpl instance
│    Leaking: NO (TopicFragment↓ is not leaking)
│    ↓ FragmentManagerImpl.mFragmentStore
├─ androidx.fragment.app.FragmentStore instance
│    Leaking: NO (TopicFragment↓ is not leaking)
│    ↓ FragmentStore.mActive
├─ java.util.HashMap instance
│    Leaking: NO (TopicFragment↓ is not leaking)
│    ↓ HashMap.table
├─ java.util.HashMap$Node[] array
│    Leaking: NO (TopicFragment↓ is not leaking)
│    ↓ HashMap$Node[].[0]
├─ java.util.HashMap$Node instance
│    Leaking: NO (TopicFragment↓ is not leaking)
│    ↓ HashMap$Node.value
├─ androidx.fragment.app.FragmentStateManager instance
│    Leaking: NO (TopicFragment↓ is not leaking)
│    ↓ FragmentStateManager.mFragment
├─ dev.hossain.android.research.researchtopic.TopicFragment instance
│    Leaking: NO (Fragment#mFragmentManager is not null)
│    ↓ TopicFragment.adapter
│                    ~~~~~~~
├─ dev.hossain.android.research.researchtopic.TopicsAdapter instance
│    Leaking: UNKNOWN
│    ↓ TopicsAdapter.mObservable
│                    ~~~~~~~~~~~
├─ androidx.recyclerview.widget.RecyclerView$AdapterDataObservable instance
│    Leaking: UNKNOWN
│    ↓ RecyclerView$AdapterDataObservable.mObservers
│                                         ~~~~~~~~~~
├─ java.util.ArrayList instance
│    Leaking: UNKNOWN
│    ↓ ArrayList.elementData
│                ~~~~~~~~~~~
├─ java.lang.Object[] array
│    Leaking: UNKNOWN
│    ↓ Object[].[0]
│               ~~~
├─ androidx.recyclerview.widget.RecyclerView$RecyclerViewDataObserver instance
│    Leaking: UNKNOWN
│    ↓ RecyclerView$RecyclerViewDataObserver.this$0
│                                            ~~~~~~
├─ androidx.recyclerview.widget.RecyclerView instance
│    Leaking: YES (View detached and has parent)
│    mContext instance of dagger.hilt.android.internal.managers.ViewComponentManager$FragmentContextWrapper, wrapping activity dev.hossain.android.research.MainActivity with mDestroyed = false
│    View#mParent is set
│    View#mAttachInfo is null (view detached)
│    View.mID = R.id.recycler_view
│    View.mWindowAttachCount = 1
│    ↓ RecyclerView.mParent
╰→ androidx.constraintlayout.widget.ConstraintLayout instance
​     Leaking: YES (ObjectWatcher was watching this because dev.hossain.android.research.researchtopic.TopicFragment received Fragment#onDestroyView() callback (references to its views should be cleared to prevent leaks))
​     key = 9760321c-31bc-4589-8e1b-ab07f99f81ec
​     watchDurationMillis = 22416
​     retainedDurationMillis = 17416
​     mContext instance of dagger.hilt.android.internal.managers.ViewComponentManager$FragmentContextWrapper, wrapping activity dev.hossain.android.research.MainActivity with mDestroyed = false
​     View#mParent is null
​     View#mAttachInfo is null (view detached)
​     View.mWindowAttachCount = 1

METADATA

Build.VERSION.SDK_INT: 29
Build.MANUFACTURER: Google
LeakCanary version: 2.4
App process name: dev.hossain.android.research
Analysis duration: 11200 ms

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.