Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Modularizing your Android App

Modularizing your Android App

This PPT is about Modularising your Android App using dynamic delivery.

Himanshu Singh

October 12, 2019
Tweet

More Decks by Himanshu Singh

Other Decks in Technology

Transcript

  1. Create an Android Project (App Module) Goto File-> New ->

    New Module and select Dynamic Feature Module (>Kitkat)
  2. class MainActivity : AppCompatActivity() { lateinit var splitInstallManager: SplitInstallManager lateinit

    var request: SplitInstallRequest val DYNAMIC_FEATURE = "news_feature" override fun onCreate(savedInstanceState: Bundle?) { .... } } In App’s MainActivity
  3. override fun onCreate(savedInstanceState: Bundle) { .... initDynamicModules() } private fun

    initDynamicModules() { splitInstallManager = SplitInstallManagerFactory.create(this) request = SplitInstallRequest .newBuilder() .addModule(DYNAMIC_FEATURE) .build(); } In App’s MainActivity
  4. In App’s MainActivity override fun onCreate(savedInstanceState: Bundle) { ........ buttonClick.setOnClickListener

    { if (!isDynamicFeatureDownloaded(DYNAMIC_FEATURE)) { downloadFeature() } else { buttonDeleteNewsModule.visibility = View.VISIBLE buttonOpenNewsModule.visibility = View.VISIBLE } } }
  5. In App’s MainActivity private fun downloadFeature() { splitInstallManager.startInstall(request) .addOnFailureListener {

    //on Failure Handle } .addOnSuccessListener { buttonOpenNewsModule.visibility = View.VISIBLE buttonDeleteNewsModule.visibility = View.VISIBLE } .addOnCompleteListener { } }
  6. In App’s MainActivity buttonOpenNewsModule.setOnClickListener { val intent = Intent() .setClassName(this,

    "com.mindorks.news_feature.newsloader.NewsLoaderActivity") startActivity(intent) }
  7. In App’s MainActivity buttonOpenNewsModule.setOnClickListener { val intent = Intent() .setClassName(this,

    "com.mindorks.news_feature.newsloader.NewsLoaderActivity") startActivity(intent) }
  8. In App’s MainActivity buttonDeleteNewsModule.setOnClickListener { val list = listOf(DYNAMIC_FEATURE) splitInstallManager.deferredUninstall(list)

    .addOnSuccessListener { buttonDeleteNewsModule.visibility = View.GONE buttonOpenNewsModule.visibility = View.GONE } }