Skip to content

Performance optimization: Consolidate Handler instances #97

@callebtc

Description

@callebtc

Description:
Multiple Handler instances are created across the app when a single shared instance could be used, leading to unnecessary resource usage.

Current Handler Usage:

  • PosUiCoordinator.kt: mainHandler
  • BalanceCheckActivity.kt: mainHandler
  • Other activities likely creating their own handlers

Issues:

  1. Unnecessary resource allocation
  2. Multiple Handler instances for the same purpose
  3. Potential handler leak if not cleaned up properly

Fix Instructions:
Create a shared Handler utility:

object HandlerUtils {
    val mainHandler: Handler by lazy { Handler(Looper.getMainLooper()) }
    
    fun postDelayed(action: () -> Unit, delayMillis: Long) {
        mainHandler.postDelayed(action, delayMillis)
    }
    
    fun post(action: () -> Unit) {
        mainHandler.post(action)
    }
    
    fun removeCallbacks(action: Runnable) {
        mainHandler.removeCallbacks(action)
    }
}

Usage:

// Replace individual Handler instances:
// private val mainHandler = Handler(Looper.getMainLooper())

// With shared utility:
HandlerUtils.postDelayed({ updateUI() }, 1000)

Benefits:

  • Reduced memory usage
  • Centralized handler management
  • Easier cleanup and lifecycle management

Priority: Low - performance optimization

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions