Sunday, April 28, 2013

Android's matryoshka problem II

This is not my post,but a copy of an important post by another developer who's  web host was over ran by the large traffic numbers, its the most import post of the year imho:

Android's matryoshka problem

Android has a fragmentation problem. No, not that fragmentation problem. The Fragments fragmentation problem.
Way back when Honeycomb was released, Google introduced Fragments to make development for both tablets and phones a bit easier. Activities still remained the way to structure screens but now screens could have multiple fragments inside them, each with its own lifecycle.
The classic example is the List and Detail fragments - each might be alone in an Activity on phones but go together on a tablet.
And all was good. For those 10 Honeycomb developers.

Fragments are special

In order to give all developers this neat new way of making apps, you'd need to have it backported to older Android versions. Google did that under the name of theSupport Library.
The support library is a weird beast - it doesn't just provide a backward-compatible layer, it entirely reimplements the Fragments infrastucture. Even on post-Honeycomb devices, the Fragment support still comes from the library and not the base OS. (This will be important later on)

Russian dolls are neat

The main problem with using Fragments for anything remotely complicated was that all communication between fragments had to go through the Activity containing them. Nested Fragments were unsupported and led to all sort of lifecycle bugs. Until API level 17, that is.
Jelly Bean 4.2 finally introduced Nested Fragments. And they were added to the Support Library, too! This was an architectural dream come true! Neat encapsulation of visual elements and business logic, no messy Activities, all is great!
Yeah, about that..

Top three most annoying bugs with nested fragments

Link: Play Store I made a demo app showcasing these bugs Source code
Terminology: root fragments are the fragments that were added to the Activity's FragmentManager. Anything else is a nested fragment. Same rules for the fragment managers

1. Animating nested fragments is half-impossible

Link: Stack OverflowNested fragments disappear during transition animation
The bug: If you, like me, are working on a relatively modern application, you want your UI to be smoothly animated. The FragmentManager allows you to set transitions for any transaction. Except, the exit animations will always cause the nested fragments to disappear when the animation starts.
The reason: Fragments have a "nested" lifecycle. That is, the nested fragments are stopped before their parent. Because the root fragment manager doesn't know about them, their View hierarchy is yanked before the animation starts. The root fragment will still animate correctly.
The fix: See the Stack Overflow StackOverflow question for a really hacky workaround. Essentially, you cache the visible state of the root fragment and set this cache as a background. Unfortunately, it does cause a complete redraw (along with possible layout issues)

2. setRetainInstance is inherited

Backround: Fragments can request to have their instance retained and not recreated from scratch when the parent Activity undergoes a configuration change (e.g., screen orientation change)
The bug: Nested fragments inherit the retain instance status of their parent fragment.
The reason: I've not investigated this in detail, just noted it and calmly put down the lock of hair I'd pulled off of my head.
The fix: None that I'm aware of.
Discussion: This might seem like a tiny little thing but it has deep consequences. I prefer to have all fragments recreated as it ensures that they can serialise their state correctly (especially ones that have views). However, I also have view-less fragments for things like network traffic and interaction with external libraries where you might set a listener that needs to be retained. Such fragments will not be retained if they are nested under something with a view hierarchy. The solution I'm currently employing uses static instances, weak references to the fragment and manual logic to redeliver the callbacks. It's messy.

3. onActivityResult is broken

Link: Stack Overflow onActivityResult() not called in new nested fragment API
This one is the most troubling, actually. You are very likely to hit it, if you ever start activities from nested fragments. It can strike in unexpected ways, for example when opening a Session via the Facebook SDK.
The bug: Activity results will be swallowed up or straight-out misdelivered for any activity started from a nested fragment.
The reason: The support library modifies the requestCode to include a fragment index in the top 16 bits. This index is relative to the fragment's fragment manager, which might be nested. However, the activity assumes that the index is within its own fragment manager, so will misdeliver the result. Fragments will also not propagate the result to any of their children.
The solution: Propagate results manually from any root fragment to its children.
The twist: The native implementation works flawlessly. Better, actually, since the Activity is never notified. Thanks, Google! I think.
I hope you enjoyed this little gallery. I certainly had fun making it.

Saturday, April 27, 2013


I was not wrong but some of the details I had backwards. Yes,we will get a preview of KeyLimePie at Google IO 2013.

However, the release that is coming out in May 2013 is Jelly Bean 4.3. At least to the data leaking out about Google testing 4.3.

I do not have any feature specific details. I would like to see SQLcipher supported but I do not think that might be until Android 5.0 or Android 6.


In A Use Case I had referred to the situation whereas a mobile android developer realizes that the stock options of a startup might not be worth it. Lets expand it.

Our assumptions are that the developer was bright enough to sin on only with a startup with series funding and the startup allowed the developer to do a remote/telecommute so as the developer could given the difference in living costs bank the money.

Even if by some magic you get between 1% and 3%, that is still about $2 million for the stock options.And remember that is money you cannot count on to be there.

But, we have this large expansion in people's interest in coding an application. The $5000 to $10000 that trainers get per student probably is only sustainable at low levels but not at a large  scale due to travel to training location, etc.

But, certainly at the lower $39 to $59 per online course you could scale into hundreds of thousands. what I am suggesting here is the developer did a revenue mix of services that scale,selling of both consumer and non consumer apps and tools it would be a dependable revenue stream as long as the developer keeps in mind that its not a high enterprise Oracle rate but a low rate that due to being able to scale to a large number.

Friday, April 26, 2013

An Android Rockstar

From time to time I get inquiries from people clearly clueless about hiring someone other them themselves. They tend to use hype terms, etc.

Lets make this simple, a normal person who wants to hire someone else would oh I guess load my sample android applications on their android device and play with them. If they are luck enough to have java coding experience they may even look at my code at my code repositories.

If you are a startup and cannot manage those two things than we have nothing to talk about and any hype phrase you are using to get me to respond is just a con game.

If you are going to recruit an android developer do the damn work, do not ask me to do that work for you.

Thursday, April 25, 2013

Using Groovy GAnt to build android apps

While the article probably will be in  May, you can follow the progress by comparing GWSAntDroid to GWSGAntDroid.

Tuesday, April 23, 2013 secret

So you attempt to find something on and notice that the UI sucks. The secrete is to use google: keyword

Monday, April 22, 2013

Using Groovy to Build Android Apps

If you want a sneak peak at using groovy to build android apps, the building part see my GAnt build file. Its only the beginning with two targets and some closures.

I should have an alpha sometime this week for you tokick the tires.

Sunday, April 21, 2013

A Use Case

A Use Case, Joe developer knows that any thing but a startup close to or in series round funding is a suckers bet. Even in a startup who has series round funding it is still a suckers bet as far as the stock options beyond that high developer salary to work 60 hours per week pretending its 40.

But Joe the developer knows if does some auditing of his own developer process,dev tools, etc he will find ways to automate away the inefficiencies and thus be in the position to on the side push out some applications to get some traction.

This way Joe the developer becomes the Angel investor in that he is using his skill and engineering skills as capital to place some intelligent bets in some areas of investment interest.

Saturday, April 20, 2013

An Android MoonShot

We have some things voice intelligence via Google services, Google Now but still no dynabook and its 50 or so years later.  Part of that problem is the computer language tools we use.

Java is not a Turing complete computer language,in Turing complete languages both data and code are treated uniformly. In the dynabook case of the full AI system what is missing is the crowd-sourcing of AI components or the user generated AI components.

If we had that than the boot-strapping of the system for dynabook than can begin as far as all the user generated AI components being able to be strung to together into something new that  has its sum greater than the parts.

But how we do that with the java limitations in place on android as we cannot on-the-fly generate new bytecode. Remember, it would have to small and light-weight.

We also have this neat thing in Android that if I set permissions to not world-wide on an application generated file this than gets stored in the application data folder of an android application and you can write code so that the application and user can change that file.

It would seem that my task in completing a Symbolic library for my scientific android calculator could be extended to do a simplistic LISP engine that runs within the android application context and allows an AI construction as both the data and code of the file get to be modified.

I am not talking about LUA, I am talking about the calculator application being extended with new AI features by the end user and in their control.

In the long term than extend it beyond just calculator functions to become a full android part with the basic understanding of all the android stuff intents, etc.

Thursday, April 11, 2013

HoloEverywhere softerror

In using the compat libs actionbarsherlock and holoeverywhere I may have found a soft error in holoeverywhere. Let me explain.

In using holoeverywhere you have to extend Fragment class from HE when using fragments. But most of using fragments have the desire to override onCreateView. In current HE that is makred as final in the -HoloFragment class of part of HE. Thus I have opened up an issue to change that modifier.