🤖
Android Tips
  • 🤖AOSP
    • Clone AOSP repository
    • Directory Structure
    • Setup IDE
      • Setup VSCode
    • Build
      • BluePrint for Application Project
      • BluePrint for Android Library Project
    • Manifest
      • sharedUserId
      • persistant
  • Gradle
    • Create Custom Build Config Variables
    • Create Custom manifest Variables
    • Make app debugable
  • Android Process
    • Find a process by name
    • Kill a process by Id
  • Catch any exception in Android
  • 🎨Theming
    • Theming
      • RRO
        • RRO Internals
        • RRO classes in AOSP
        • RRO Example
        • RRO Permission
      • Fabricated RRO (FRRO)
        • FRRO Example
        • Permission
  • Lifecycle
    • Basics
      • Lifecycle
        • Activity
        • Fragment
          • Fragment add
    • Lifecycle Aware Custom Class
  • â„šī¸Interview
    • Interview Questions
    • Architecture Pattern
      • MVC Architecture pattern
      • MVP Architecture Pattern
      • MVVM Architecture Pattern
  • â†”ī¸AIDL
    • Simple AIDL Communication
      • Creating an AIDL file
      • Create an AIDL server
      • Create AIDL client
      • Limitations
    • AIDL with callback
      • Create AILD interfaces
      • Create an AIDL server
      • Create AIDL client
Powered by GitBook
On this page
  1. AIDL
  2. Simple AIDL Communication

Create AIDL client

An AIDL client connects to a exposed AIDL Service via Binders

An AIDL client is an app that binds to an AIDL service, calls API, shows response inside its own views.

Steps:

  1. Create a service connection:

     private var aidlService: ICalculator? = null
     private val serviceConnection = object : ServiceConnection {
         override fun onServiceConnected(name: ComponentName?, service: IBinder?) {
             aidlService = ICalculator.Stub.asInterface(service)
             Toast.makeText(applicationContext, "Service Connected", Toast.LENGTH_LONG).show()
         }
    
         override fun onServiceDisconnected(name: ComponentName?) {
             aidlService = null
             Toast.makeText(applicationContext, "Service Disconnected", Toast.LENGTH_LONG).show()
         }
     }
  2. Connect to AIDL service via Binders.

     val serviceIntent = Intent()
     serviceIntent.component = ComponentName(BuildConfig.AIDL_PACKAGE, BuildConfig.AIDL_SERVICE)
     bindService(serviceIntent, serviceConnection, BIND_AUTO_CREATE)
  3. Call methods of AIDL after successful connection:

     aidlService?.add(2, 2)?.let {
         Toast.makeText(
             applicationContext,
             String.format(Locale.getDefault(), "Sum is: %d", it),
             Toast.LENGTH_LONG
         ).show()
     }
PreviousCreate an AIDL serverNextLimitations

Last updated 1 year ago

â†”ī¸