Cover photo
Mattias Isegran Bergander
Works at Consat Telematics
Attended Chalmers University of Technology
405 followers|1,314,784 views


"Must read" for android developers.
"How should I design my Android application? What kind of MVC pattern should I use? What should I use for an event bus?"

We often see questions from developers that are asking from the Android platform engineers about the kinds of design patterns and architectures they use in their apps. But the answer, maybe surprisingly, is we often don't have a strong opinion or really an opinion at all.

Should you use MVC? Or MVP? Or MVVM? I have no idea. Heck, I only know about MVC from school and had to do a Google search to find other options to put here.

This may be surprising, because Android could feel like it has strong opinions on how apps should be written. With its Java language APIs and fairly high-level concepts, it can look like a typical application framework that is there to say how applications should be doing their work. But for the most part, it is not.

It is probably better to call the core Android APIs a "system framework." For the most part, the platform APIs we provide are there to define how an application interacts with the operating system; but for anything going on purely within the app, these APIs are often just not relevant.

That said, the Android APIs can often look different (or higher level) from what one typically expects in an operating system, which may easily lead to confusion about how they should be used.

For an example of this, let's consider how an operating system defines "how to run an app." In a classic system, this is basically the contract it has with an application about when it should run:

int main(...) {
// My app goes here!

So the operating system starts the app, calls its main() function, and the app goes off and runs and does what it wants until it decides it is done. And clearly it is not saying anything here about what the app should be doing or how it should be designed within that main function -- it's a pretty pure blank slate.

In Android, however, we explicitly decided we were not going to have a main() function, because we needed to give the platform more control over how an app runs. In particular, we wanted to build a system where the user never needed to think about starting and stopping apps, but rather the system took care of this for them... so the system had to have some more information about what is going on inside of each app, and be able to launch apps in various well-defined ways whenever it is needed even if it currently isn't running.

To accomplish this, we decomposed the typical main entry point of an app into a few different types of interactions the system can have with it. And these are the Activity, BroadcastReceiver, Service, and ContentProvider APIs that Android developers quickly become familiar with.

These classes may look like they are telling you how the internals of your app should work, but they are not! In fact, they are all about how your app needs to interact with the system (and how the system can coordinate its interaction with other apps). As long as that interaction with the system happens, we don't really care what goes on inside of the app.

To illustrate, let's briefly look at these different APIs and what they really mean to the Android system.


This is the entry into an application for interacting with the user. From the system's perspective, the key interactions it provides with the app are:

• Keep track of what the user currently cares about (what is on screen) to ensure the process hosting that is kept running.
• Know that previously used processes contain things the user may return to (stopped activities), and thus more highly prioritize keeping those processes around.
• Help the application deal with the situation where its process is killed so the user can return to activities with their previous state restored.
• Provide a way for applications to implement user flows between each other, coordinated by the system. (The most classic example here being share.)

What we don't care about:

Once we have gotten in to this entry-point to your UI, we really don't care how you organize the flow inside. Make it all one activity with manual changes to its views, use fragments (a convenience framework we provide) or some other framework, or split it into additional internal activities. Or do all three as needed. As long as you are following the high-level contact of activity (it launches in the proper state, and saves/restores in the current state), it doesn't matter to the system.


This is a mechanism for the system to deliver events to the application that may be outside of a regular user flow. Most importantly, because this is another well-defined entry into the app, the system can deliver broadcasts to apps even if they aren't currently running. So, for example, an app can schedule an alarm to post a notification to tell the user about an upcoming event... and by delivering that alarm to a BroadcastReceiver of the app, there is no need for the app to remain running until the alarm goes off.

What we don't care about:

Dispatching events within an app is an entirely different thing. Whether you use some event bus framework, implement your own callback system, whatever... there is no reason to use the system's broadcasting mechanism, since you aren't dispatching events across apps. (In fact there is good reason not to -- there is a lot of unnecessary overhead and many potential security issues if using a global broadcast mechanism for the internal implementation of an app.) We do provide the LocalBroadcastManager convenience class that implements a purely in-process intent dispatching system with a similar API to the system's APIs, if you happen to like them. But again, there is no reason to use that over something else for things going on purely within your app.


A general-purpose entry point for keeping an app running in the background for all kinds of reasons. There are actually two very distinct semantics services tell the system about how to manage an app:

Started services are simply telling the system to, for some reason, "keep me running until I say I am done." This could be to sync some data in the background or play music even after the user leaves the app. Those also represent two different types of started services that modify how the system handles them:

• Music playback is something the user is directly aware of, so the app tells the system this by saying it wants to be foreground with a notification to tell the user about it; in this case the system knows that it should try really hard to keep that service's process running, because the user will be unhappy if it goes away.

• A regular background service is not something the user is directly aware as running, so the system has more freedom in managing its process. It may allow it to be killed (and then restarting the service sometime later) if it needs RAM for things that are of more immediate concern to the user.

Bound services are running because some other app (or the system) has said that it wants to make use of the service. This is basically the service providing an API to another process. The system thus knows there is a dependency between these processes, so if process A is bound to a service in process B, it knows that it needs to keep process B (and its service) running for A. Further, if process A is something the user cares about, than it also knows to treat process B as something the user also cares about.

Because of their flexibility (for better or worse), services have turned out to be a really useful building block for all kinds of higher-level system concepts. Live wallpapers, notification listeners, screen savers, input methods, accessibility services, and many other core system features are all built as services that applications implement and the system binds to when they should be running.

What we don't care about:

Android doesn't care about things going on within your app that don't have any impact on how it should manage your process, so there is no reason to use services in these cases. For example, if you want to start some background operation to download data for your UI, you should not use a service for this -- it is actually important to not be telling the system to keep your process running while doing this, because it really doesn't need to be and the system would be better off having more freedom in managing it with other things the user is doing.

If you just make a simple background thread (or whatever non-service mechanism you want) to do the downloading, you will get the semantics you want: while the user is in your UI, the system will keep your process running for that, so the download will never be interrupted. When they leave your UI, your process will still be kept around (cached) and able to continue downloading, as long as its RAM isn't needed elsewhere.

Likewise for connecting different parts of your app together, there is no reason to bind to a service that is running in the same process as the one binding to it. Doing so is not actively harmful -- the system just sees a dependency from the process to itself so doesn't try to keep it around any more than usual -- but it is a bunch of unnecessary work for both you and the system. Instead, you can just use singletons or other normal in-process patterns for connecting pieces of your app together.


Finally, the ContentProvider is a fairly specialized facility for publishing data from an app to other places. People generally think of them as an abstraction on a database, because there is a lot of API and support built in to them for that common case... but from the system design perspective, that isn't their point.

What these are to the system is an entry-point into an app for publishing named data items, identified by a URI scheme. Thus an app can decide how it wants to map the data it contains to a URI namespace, handing out those URIs to other entities which can in turn use them to access the data. There are a few particular things this allows the system to do in managing an app:

• Handing out a URI doesn't require the app remain running, so these can go all over the place with the owning app being dead. Only at the point where someone tells the system, "hey give me the data for this URI" does it need to make sure the app owning that data is running, so it can ask the app to retrieve and return the data.

• These URIs also provide an important fine-grained security model. For example, an application can place the URI for an image it has on the clipboard, but leave its content provider locked up so nobody can freely access it. When another app pulls that URI off the clipboard, the system can give it a temporary "URI permission grant" so that it is allowed to access the data only behind that URI, but nothing else in the app.

What we don't care about:

It doesn't really matter how you implement the data management behind a content provider; if you don't need structured data in a SQLite database, don't use SQLite. For example, the FileProvider helper class is an easy way to make raw files in your app available through a content provider.

Also, if you are not publishing data from your app for others to use, there is no need to use a content provider at all. It is true, because of the various helpers built around content providers, this can be an easy way to put data in a SQLite database and use it to populate UI elements like a ListView. But if any of this stuff makes what you are trying to do more difficult, then feel free to not use it and instead use a more appropriate data model for your app.
69 comments on original post
Add a comment...
Great! +Mike Penz accepted my pull request adding material multi-directional swipe leave behinds, actions and undo into his FastAdapter library. It's currently just in the sample app but might turn into something even more reusable.


#androiddev #anddev
Add a comment...
Just had to share this one. Reality. If you haven't checked out his "pixelpushing" posts before, now is the time. Just click the pixelpushing hash tag, for more enjoyable content :)

"At universities they should make every developer write an app with Node.js, deploy it to production, then try to update the dependencies 3 months later. The only downside is we would have zero new developers coming out of computer science programs" and I was all like...

#pixelpushing #webpushing

"At universities they should make every developer write an app with Node.js, deploy it to production, then try to update the dependencies 3 months later. The only downside is we would have zero new developers coming out of computer science programs" and I was all like...
18 comments on original post
Add a comment...
Great, soon we can easily convert all photos from "Original quality" to "high quality" . Since the really nice raise in the quality limits for free storage I think a lot of people want to do this. In a few days it should be available on the web, under settings:
We have two features that will begin rolling out on Android today:

Helping users free up storage space on their Android device:
On the Settings screen, users will now see a “Free Up Space” button. Clicking on the button will prompt the user to bulk-delete copies of photos that have already been backed up from their device. To prevent device copies from being accidentally deleted, we’re asking users to double-confirm their intent during the ‘Free Up Space’ flow.

Users who are backing up their photos in High quality may now also receive an Assistant card prompting them to bulk delete device copies when they’re nearing the storage limit on their devices (currently only users who are backing up at Original quality receive these cards).

Deleting photos from SD-card enabled devices
We’re rolling out a fix that will allow users on certain SD-card enabled devices to delete photos stored on an SD card. This should prevent the issue of a photo continuing to show up in the Photos view despite being deleted, a frustrating experience for users.

We have one feature that will begin rolling out on the Web on Wednesday:

Downgrade previously uploaded photos from “Original quality” to “High quality”
When users choose to backup their photos and videos to Google Photos, we allow photos to be uploaded in two ways:
“Original quality” (large file, full resolution). These photos count against a user’s Google storage quota.
“High quality” (smaller file, compressed file). These photos don’t count against a user’s Google storage quota.

If a user joined Google Photos and selected the “Original quality’ setting for their photos, but changed their mind, they could have future media backed up in “High quality”. However, for media already backed up in “Original quality” before then, users were in an awkward state: they had no way to downgrade that media to “High quality”.

With this update, users will be able to downgrade previously backed up photos from “Original quality” to “High quality” by visiting from their computer and clicking ‘Recover Storage’.

94 comments on original post
Lennart Kolmodin's profile photoMattias Isegran Bergander's profile photo
Already on that one +Lennart Kolmodin  :)
Add a comment...
So the new demo mode in System UI tuner in Android developer preview 2 is great for taking clean screenshots. It even does the customary "the current Android version as the clock time". Though that part has a flaw, 5.20pm with a 24h clock is 17.20... Should've used 5.20am
Mattias Isegran Bergander's profile photoKyle Smaagard's profile photo
Add a comment...
Updated Preview 1 builds for Nexus 5X, 6P and 9/9G addressing some performance issues with the original preview 1. Quick testing and it looks promising. Nothing for N6 though.
Check for system updates the normal way, you will get it at once if you are in the beta program.

#android #androiddev
New Dev Preview 1 Builds for Nexus 5X, 6P, 9, and 9G
Starting today, you'll find new builds for the Nexus 5X and 6P (NPC56W) and for the Nexus 9 and Nexus 9 4G (NPC56X) which addresses some performance issues.

OTA updates should be rolling out now.

You can also find the updated images at

As per community guidelines, Android Beta, OTA, and device questions should go to the Android Beta community:
Add a comment...

That (great actually) feeling you get when you've just finished refactored an app from ListViews to RecyclerViews with all bells and whistles (decorations, animations, drag 'n drop, ...) and recommended tricks/ways of doing things from various google talks for performance and stability, and various features ranging from drag and drop, live search/filter, undo snackbars, etc etc. Literally just starting to think about how to cleanly separate that out into some reusable stuff across various apps, when +Mike Penz releases a clean solid library to simplify all that and a lot more (and he has a good track record with libraries and quality making the decision a nobrainer). Including my next features on the todo list with overlay and sticky headers and material index.

Thanks +Mike Penz, much appreciated, will convert directly to use FastAdapter!

FastAdapter my newest library is now in v0.8.1

It is an easy Adapter api which simplifies all the work of writing a good and fast adapter. Stop wasting time by writing an adapter, and all the logic to animate, remove, expand, reorder items. Everything is handled by the FastAdapter for you. This library was written with a lot of detail on speed, and stability.

Getting a Recycler filled with items is now as easy as writing your Item and the logic how it should look like. Fill the adapter with your item's and it is ready.

Just try the sample and see how easy and fast it is.

What do you get:
- Click / LongClick / Touch listeners
- Single / Multi - Selection
- Expandable items
- Saves the state of selections / expandable items inside the SavedInstanceState
- Simple Drag & Drop based on (
- Very fast
- Flexible
- Useful helpers which make your life easier

There is also a sample app:
1 comment on original post
Add a comment...
Impressive amount of references to Star Wars included in this weather report, well done.

#starwars   #starwarstheforceawakens  
Add a comment...
No fees on calls to France via Hangouts app on iOS and Android
We're thinking of you, Paris. No fees on calls to France, via Hangouts. #ParisAttacks

Android →
iOS →
255 comments on original post
Add a comment...
That's nice, one of my personal apps got reviewed* and it got a 4.7 rating out of 5! Yeah me! OK and my wife who had some very specific design ideas based on reality and actual usage...

The app in question is the yoga specific edition of my timer (continuous flow of timers) apps that I made for my wife.

Non-yoga version:

And yes I'm working on a total material redesign of it and more features for this and the non-yoga version. Though it was already a bit material-ish (paper, elevations, layers, colors wise I mean, not interaction).

Anyone else who would approve of a material design upgrade?

*=No not paid for or anything, totally out of the blue for me :)

#android   #apps   #androidapps   #yoga  
Stefan Janson's profile photo
gratz! :)
Add a comment...
Android M developer preview 2 is out, OTA update (I got it through system update) or download the entire image.

OTA link from my logcat for Nexus 6 if you don't have it available in your system update settings and want to do a manual OTA:
Add a comment...
Seriously,  we are able to do this? Wow. Dwarf planet Pluto passes in front of a (very) distant star and we can detect the ridiculously faint and fast moving shadow it casts on earth (and thereby analyse the spectra gettings us information about Pluto's atmosphere). Just wow. 
Just two weeks before our New Horizons spacecraft reaches Pluto, the SOFIA telescope happened to be in the Southern Hemisphere right as the dwarf planet passed between a distant star and the Earth. This special event will allow us to connect these remote observations to the flyby data of the New Horizons mission. Details: #PlutoFlyby 
24 comments on original post
Add a comment...
Mattias's Collections
Programmer by day & night and the family in between!
A runner and a computer and programming geek, currently mostly Java, Android, C++, C#, ... Black belt 2 Dan martial arts (Bujinkan). Trail ultra-marathon 45km finisher.

My own Android apps:
  • Timer Flow -One timer leads to the next, can repeat groups of them, for workouts etc
  • Yoga Timer -Specialized yoga version of Timer Flow
  • House alarm -Home alarm remote for certain home alarm models
Android apps in development:
  • Unannounced "secret" RTS Game
Bragging rights
2 Dan Bujinkan black belt. Committed code to Java 6. Best customer praise about delivered software: "Euphoric chock". Was in the Robocode top 3. Trail ultra-marathon 45k finisher.
  • Chalmers University of Technology
    M.Sc. Computer Science & Engineering, 1996 - 2000
MSc CS&E, System Architect/Developer
  • Consat Telematics
    MSc CS&E, System Architect/Developer, 2009 - present
  • Consat Engineering
    2005 - 2009
  • Pilotfish Networks
    1999 - 2005
Basic Information
Other names
Mattias Isegran Bergander's +1's are the things they like, agree with, or want to recommend.
Nu finns Google Duo i svenska Play Store - Swedroid

Googles nya app för videosamtal, Duo, har blivit tillgänglig i svenska Play Store nu under kvällen. Svenska släppet kom inte mer än två daga

Polar M600 – en Android Wear-klocka med GPS och träningsfokus - Swedroid

Polar har introducerat M600 vilket är en Android Wear-smartklocka med fokus på träning. Enheten erbjuder GPS+GLONASS, optisk pulsmätare och

Pokémon GO – Android-appar på Google Play

Venusaur, Charizard, Blastoise, Pikachu, and many other Pokémon have been discovered on planet Earth! Now’s your chance to discover and capt

Flight Lite - enkla ikoner – Android-appar på Google Play

- LITE VERSION - Full version här: Lite versionen har de flesta av de full

Linjer Gratis - Icon Pack – Android-appar på Google Play

- GRATIS VERSION -Fullständig version här: Det

Google Play Developer Console – Android-appar på Google Play

Få tillgång till data från Google Play Developer Console på din Android-enhet. Granska appens statistik och ekonomiska resultat. Få aviserin

Google Foto – Android-appar på Google Play

På Google Foto samlas alla dina foton och videoklipp. De ordnas automatiskt och är sökbara så att du snabbt kan hitta dem. Det är fotogaller

Clash Royale – Android-appar på Google Play

Enter the Arena! From the creators of Clash of Clans comes a real-time multiplayer game starring the Royales, your favorite Clash characters

Odyssey Watch Face – Android-appar på Google Play

This watch face for Android Wear takes elements of classic pilot watches and combines them with futuristic design. Travel through space and

Iconics Library – Android-appar på Google Play

If you are an app developer you will know the problem. You start an app but require many different icons, in different sizes (ldpi, mdpi, hd

Headspace - meditation – Android-appar på Google Play

Using proven meditation and mindfulness techniques we’ll show you how to train your mind for a healthier, happier, more enjoyable life.How i

SwiftKey Beta – Android-appar på Google Play

Welcome to the SwiftKey beta program - here you can test early performance updates, new unreleased features & customizations, and special th

Mattias: Shared thoughts

There is so much stuff to learn in so many areas. It is all very humbling. Sometimes you find an article, presentation, blog post, etc. that

Slack – Apps para Android no Google Play

All your team communication in one place, instantly searchable, available wherever you go. That's Slack.* Real time messaging, file sharing,

Skype – Applications Android sur Google Play

Dites bonjour à vos proches par messagerie instantanée ou en leur passant un appel vidéo ou audio gratuit sur Skype. Rejoignez les millions

Dolphin Jetpack – Android-appar på Google Play

Get Dolphin Jetpack to speed up your Dolphin Browser and enjoy more cool features. Dolphin Jetpack uses Dolphin’s very own HTML5 rendering e

Flynx - Read the web smartly – Android Apps on Google Play

Flynx helps you open articles and links from all your favorite apps like Facebook, Twitter, Whatsapp, Google+, etc. in a revolutionary new w

OneDrive – Android-alkalmazások a Google Playen

A OneDrive-on egy helyen tárolhatja és megoszthatja minden személyes és munkaanyagát. Az ingyenes tárhelyre feltöltött személyes fájljait bá

Bloons Monkey City - Google Play의 Android 앱

Create, upgrade, and customize your very own Bloons Monkey City in this groundbreaking blend of city building and tower defense awesomeness!

Excellent lunch, good quality buffet with two main courses with lots of different sides and a smorgasbord of other small complimentary dishes and choices.
Public - in the last week
reviewed in the last week
Fantastiskt fint, fina spår av olika typ inkl stigar och början på vildmarksleden som går hela vägen till Hindås.
Public - 2 weeks ago
reviewed 2 weeks ago
Fin utsikt förstås och lugnt och trevligt!
Public - 3 weeks ago
reviewed 3 weeks ago
Excellent food and snacks, even healthy and vegan options.
Public - 4 weeks ago
reviewed 4 weeks ago
184 reviews
Public - 3 weeks ago
reviewed 3 weeks ago
Grymma erbjudanden ibland och skönt med en butik ibland som dessutom funkar bra på webben.
Public - 3 weeks ago
reviewed 3 weeks ago
Mysigt, traditioner. Mycket folk i rörelse med ändå lugnt.
Public - a month ago
reviewed a month ago