Android Gets Architecture Components
Android Gets Architecture Components
Written by Mike James   
Wednesday, 31 May 2017

Is it a sign of maturity when a system gets its own architecture components? It all depends on how you look at it. 

androidapp

 

Architecture components seem to occur when the developers of a system have enough time to attempt to abstract the bigger, higher level, tasks that nearly every application has to implement. It seems that the time has arrived for Android. The preview of the Architecture Components was announced at Google I/O, but it mostly went unnoticed. 

In this preview two issues are addressed: 

  • Automatically manage your activity and fragment lifecycles to avoid memory and resource leaks

  • Persist Java data objects to an SQLite database 

The big problem with most component libraries that have the word "architecture" in their title is working out what exactly they do. For example:

"New lifecycle-aware components provide constructs to tie core components of your applications to lifecycle events, removing explicit dependency paths."

If you already know what that means you are probably wondering why anyone would have trouble with it. The problem is that Android state management is ridiculously complicated and you don't have to look far to find quite high profile apps that get it wrong.

In an ideal world the whole life-cycle issue would be swept under the carpet by the operating system. There isn't much excuse for the operating system not taking care of it all and leaving the app programmer with the fiction that their app is the only one running and never gets booted out. After all, its how the desktop has worked for a long while and mobile hardware gets more powerful everyday. 

Look at what is on offer more carefully. What we seem to have is an observer class that makes working with the different lifecycle states a little easier at the cost of learning yet another layer of software. It allows you to avoid having to code what happens to your component in the relevant event handlers of the Activity or Fragment. Instead your component can simply observe the state changes and have its own "event handlers" called automatically. 

You can use this to build lifecycle-aware components. For example, there is the ViewModel class which stores UI-related data so that it survives state changes such as screen rotation. This is basically a more sophisticated solution to the problem than the basic onSaveInstanceState and similar. The ViewModel outlives the Activity and Fragment and so provides persistent storage. When the Activity/Fragment is recreated it gets the same ViewModel instance. There is also a LiveData class that will basically only keep data fresh when there is an active observer, i.e. when some component is running and making use of the data. 

The second objective is to provide a more general data persistence:

The Android Architecture Components also simplify data persistence with the Room library. Room provides an object-mapping abstraction layer that allows fluent database access while harnessing the full power of SQLite. 

The idea is that you annotate a Java data object, create a database for them, and define a DAO class with the necessary SQL to access and modify the database:

room

 

You can find out more from the promo video and there is lots of documentation - which isn't that easy to follow:

 

 

So will I be using the architecture components?

No.

The reason is that it is only in preview and subject to change, possibly big changes. I plan to keep an eye on it and see what happens. 

There is also the small matter that it doesn't provide any databinding and doesn't offer any help in using it with the databinding library, which is a potentially a much more important development in Android programming - even if it does seem to be falling by the wayside. 

Then, of course, there is Kotlin, which changes everything. 

You could use the architecture components from Kotlin, but probably would be easier and better to wait for the Kotlin version - if there ever is one.

With turbulent times in the Android world, now is probably not the moment for an architecture library and certainly not an under-developed and probably under-resourced one. 

 

androidapp

 

More Information

Android and Architecture

Android Architecture Components

Related Articles

Android Studio 3

Kotlin - New Language For Android

 

To be informed about new articles on I Programmer, sign up for our weekly newsletter, subscribe to the RSS feed and follow us on, Twitter, FacebookGoogle+ or Linkedin.

 

Banner


More Machine Learning Applied to Google Sheets
12/06/2017

Google has just released an update to Sheets, its spreadsheet application, which extends its Explore facility to creating charts for instantly visualizing data.



New Self Mandarin Improves Versioning
06/06/2017

There's a new version of the Self programming language with new versioning systems for its key subsystems.


More News

 
 

 

blog comments powered by Disqus

 

 

Last Updated ( Wednesday, 31 May 2017 )
 
 

   
Banner
RSS feed of news items only
I Programmer News
Copyright © 2017 i-programmer.info. All Rights Reserved.
Joomla! is Free Software released under the GNU/GPL License.