Profile

Cover photo
Chris Boyle
Lives in Oxford, UK
671 followers|223,973 views
AboutPostsPhotosVideos+1'sReviews

Stream

Chris Boyle

Shared publicly  - 
 
Just published a new Puzzles release with changes from recent betas: 2 new games, night mode, more readable graphics.
Collection of 38 single-player open-source logic puzzle games, free, no ads...
1
Add a comment...

Chris Boyle

Shared publicly  - 
 
The rising crescendo of bickering and acrimony within Europe might seem to outsiders to be the inevitable result of the bitter endgame playing out between Greece and its creditors. In fact, European leaders are finally beginning to reveal the true nature of the ongoing debt dispute, and the answer is not pleasant.
1
Friedrich Sinofzik's profile photo
 
lol.. So..
Who will give them money now?
The FRIENDS from Russia? China?
Who will invest inside a country that is broken and is inefficient from all perspective?
Russian speculative capital that  started the Greek problems and leave at first sign of problems?

Or maybe go to foreign banks and get paying exorbitant fees and print more money and leave this bill for the maybe next generations pay?

Learn with Europe how to be efficient and produce and will be a big win.
Still like a 4000 years state where everyone live from the state and the state cant produce . good luck for everyone.
Portugal is learning how to leave their PAST crazy millennia  state like Greek ones to be more efficient.

Look Argentina or Venezuela... It's your future outside eurozone Greece.
Add a comment...

Chris Boyle

Shared publicly  - 
 
The release of a ‘viability assessment’ for one of London’s most high-profile developments – seen exclusively by the Guardian – sheds new light on how developers are taking advantage of planning laws to ramp up their returns
1
Add a comment...

Chris Boyle

Shared publicly  - 
 
 
Composition over Inheritance
What it means for your Activities

So we've all heard the suggestion that we should prefer composition over inheritance. For those that haven't, the idea is classes should only inherit from classes if they can fully stand in for their parent class, not just to share some behavior (more information at [0]). Despite this, I can't count how many Android projects I've been on/seen that had some BaseActivity that all of their Activities must extend from.

This can be problematic on a few fronts. The most obvious is that when Joe Newguy comes in and adds ShinyFeatureActivity, there's nothing forcing him to make sure it extends BaseActivity. Hopefully it's caught in code review. Additionally, it prevents you from extending from any other Activity class (E.g. PreferenceActivity, ListActivity...). Many of these Activity subtypes have been replaced by Fragment subtypes, but not all. Some libraries might also need their own Activity subtype.

Somewhat more insidious is that you might have some behaviors that are used in several of your Activities, and another set of behaviors for another group of Activities. Since Java doesn't support multi-inheritance, you have no choice but to put all of the behaviors into a single base class if these groups overlap. That means reduced maintainability, and possibly some performance penalties.

It's easy to see why we like to do this. Code reuse is a good thing, right? And much of our common logic needs to happen at specific points in the Activity lifecycle. Application.ActivityLifecycleCallbacks can be a pain to work with (they're passed Activities rather than living in them) and likely need to be registered in Application.onCreate() which we try to avoid.

This is where headless Fragments come in. While a lot of Android developers think of Fragments as UI components, they're really more lifecycle components. So what do I mean by "headless"? Just that onCreateView() either isn't overridden or returns null. Essentially, these are Fragments that implement some process or control that doesn't have a UI itself.

To differentiate my headless Fragments from my View oriented Fragments, I've taken to suffixing my headless Fragments with "Helper" and other Fragments with "Fragment". For example, AnalyticsHelper would be a headless Fragment for attaching my analytics logic, while HeaderFragment shows a header View for something. This is totally optional, but I've found it helpful.

Since there is no UI for these Fragments, there is no layout ID necessary to inflate into or animations to worry about, so your factory methods can be smarter and more controlled. For that matter, they can handle adding the Fragment themselves. I've created a gist [1] that shows how to do this. In Android Studio, you can add this to the "File and Code Templates" section in settings, and when you create a new class (New -> Java Class), select it in the "Kind" dropdown.

Adding FooHelper to its parent is as simple as calling FooHelper.attach(this). You'll get compiler errors telling you if the parent doesn't implement FooHelper's callback interface, and if attach() had already been called, it will return the preexisting fragment. The gist includes overloads for framework Fragments and Activities, but switching them to use support Fragments and FragmentActivity is pretty trivial. It also includes a getParent() that is a simplified version of my FragmentUtils.getParent() gist [2].

Obviously headless Fragments are more useful than just getting stuff out of your BaseActivity. They're also great for encapsulating processes that need lifecycle callbacks (or onActivityResult(), or a child FragmentManager...). The great thing about replacing BaseActivity, though, is that now you can split up the "common" logic onto single-purpose modular components, and decide for each Activity which modules you actually need. If most of your Activities need a lot of the same modules there's no reason you couldn't write a CommonComponentsHelper to pull them in, but now you're not forced to keep all your common dependencies in one base class.

[0] http://stackoverflow.com/questions/49002/prefer-composition-over-inheritance
[1] https://gist.github.com/keyboardr/ddf35148ca2c1a2bfbde
[2] https://gist.github.com/keyboardr/5455206
A file template for creating a headless Fragment. The attach() methods add the fragment to the parent if it doesn't already exist and returns the attached fragment. The methods ensure that the parent implements the parent interface. If needed, parameters may be added to the attach() methods to supply fragment arguments. - Gist is a simple way to share snippets of text and code with others.
25 comments on original post
1
Add a comment...
Have them in circles
671 people
Dominic Bartl's profile photo
krishna kumar's profile photo
Verro Krugov's profile photo
Jon Moore's profile photo
Catherine Greenwood's profile photo
Nicholas Dore's profile photo
Anders Aagaard's profile photo
TIOEE EngineeringEducation's profile photo
Becky Corlett's profile photo

Chris Boyle

Shared publicly  - 
1
Add a comment...

Chris Boyle

Shared publicly  - 
 
I always knew this day would come. The day that Facebook decided my name was not real enough and summarily cut me off fr…
1
Add a comment...

Chris Boyle

Shared publicly  - 
 
New Statesman columnist tweets displeasure after being kicked off social media site, saying she used alias to avoid being trolled
1
Add a comment...

Chris Boyle

Shared publicly  - 
 
I’m glad we’ve all agreed to stop watching Woody Allen movies, to delete R. Kelly’s songs from our music libraries. But I also think we need to stop hanging out with the rapists we actually know. Taking a stand against awful celebrities is important: it sends a clear message to our communities ...
1
Add a comment...
People
Have them in circles
671 people
Dominic Bartl's profile photo
krishna kumar's profile photo
Verro Krugov's profile photo
Jon Moore's profile photo
Catherine Greenwood's profile photo
Nicholas Dore's profile photo
Anders Aagaard's profile photo
TIOEE EngineeringEducation's profile photo
Becky Corlett's profile photo
Work
Occupation
Software Engineer
Skills
7 years' commercial experience in C++, Java, Perl, networking, Linux; also proficient in Python, C, JavaScript, Ruby, web development.
Story
Tagline
Software engineer based in Oxford
Introduction
I can usually be found writing code, dancing to gothy bleep, or performing in Lashings.

See chris.boyle.name.
Bragging rights
Ported Simon Tatham's Puzzles to Android: 100k downloads. :-)
Places
Map of the places this user has livedMap of the places this user has livedMap of the places this user has lived
Currently
Oxford, UK
Previously
Cambridge, UK - Coventry, UK - Winchester, UK - Crawley Down, UK - Basingstoke, UK
Apps with Google+ Sign-in
  • AutoCast
  • Threes!
  • Goat Simulator
Chris Boyle's +1's are the things they like, agree with, or want to recommend.
What is the DoD's Position on Backdoors in Security Systems? - Schneier ...
www.schneier.com

What is the DoD's Position on Backdoors in Security Systems? In May, Admiral James A. Winnefeld, Jr., vice-chairman of the Joint Chiefs of S

Operation Choke Point; or, We Know What's Best For You
tacit.livejournal.com

Before I can really go into the things I want to talk about, I'll need to offer you, dear readers, a bit of back story. As many folks who've

Bikes, buses, lorries oh my
rockstardinosaurpirateprincess.com

This last week hasn’t been great for cyclists in London, with 3 incidents on one day on Thursday leading to the deaths of a cyclist in South

If I Owned the Road
bikeyface.com

Recently I found myself in this situation: And I wished I could show this dude what would happen if I really did own the road. Things would

How To Ally With Survivors, Avengers Edition
www.flowerhorne.com

Hey, Captain Rogers. We need to talk. I know you're probably still behind on your reading, so you may not know what 'rape culture' is. You p

Flailing from the elbows - What to do if you’re told you can’t vote
inarticulate-tyrannosaurus.tumblr.com

I helped antidisenfranchise a friend who was wrongly told that she couldn’t vote today. The people in charge at her polling station and the

Owen Jones: if the Tories get more seats than Labour, get ready for a Ve...
www.newstatesman.com

Don't let the right tell you that if Labour come second on seats, their government would be "illegitimate".

To keep a Boeing Dreamliner flying, reboot once every 248 days
www.engadget.com

The 787 Dreamliner has been plagued with battery woes since its early days, to the point where the Federal Aviation Administration kept it f

Nonviolence as Compliance in Baltimore
www.theatlantic.com

When nonviolence begins halfway through the war with the aggressor calling time out, it exposes itself as a ruse.

Facebook Bans Disabled Trans Woman of Colour for Not Appearing Feminine ...
chrismilloy.ca

If you follow social justice activism, then you may be fortunate enough to already be familiar with Kylie Brooks. Brooks is an activist, who

What stands between young people and the streets?
england.shelter.org.uk

Everyone deserves a safety net when times are tough. But taking housing benefit away from most under 21s will put many at risk of homelessne

Just when hope and courage are called for, Labour promises bean-counting...
www.theguardian.com

Labour’s focus on cutting the deficit, means progressive voters will have to look elsewhere for inspiration

Regulation of UK estate agents handed over to Powys county council | Mon...
www.theguardian.com

Closure of Office of Fair Trading leaves Welsh council to protect homebuyers and sellers from rogue agents

Very rich people declare support for party that supports very rich people
newsthump.com

Several incredibly rich people have had their minions type a letter in which they have declared their wholehearted support for the party tha

Schneier on Security: The Democratization of Cyberattack
www.schneier.com

The Democratization of Cyberattack. The thing about infrastructure is that everyone uses it. If it's secure, it's secure for everyone. And i

Refused service because one of us "in fancy dress" (stage makeup). During #edfringe. Seriously?
Public - a year ago
reviewed a year ago
Great pizzas :-)
Food: ExcellentDecor: ExcellentService: Excellent
Public - 2 years ago
reviewed 2 years ago
Good range of food, but quite slow to serve it to our large group.
Food: Very GoodDecor: ExcellentService: Excellent
Public - 2 years ago
reviewed 2 years ago
Food: ExcellentDecor: ExcellentService: Excellent
Public - 2 years ago
reviewed 2 years ago
120 reviews
Map
Map
Map
Quality, quantity, and price all good, and the best garlic bread I've tasted. Delivery a bit slower than estimated, but this was peak time on a bank holiday Monday.
Public - 2 years ago
reviewed 2 years ago
Food: Very GoodDecor: ExcellentService: Excellent
Public - 2 years ago
reviewed 2 years ago
Food: ExcellentDecor: ExcellentService: Excellent
Public - 3 years ago
reviewed 3 years ago