Fragment view state retention: A dirty solution

This is the last part of this 6 part series about Fragment Oriented Architecture in Android applications. In the previous post I talked about managing sessions in fragment oriented application. In this post I am going to talk about retaining view hierarchy of a Fragment after removing it from container and then coming back to it by popping the backstack.

(Sample application’s source code and README)

When a fragment gets replaced by another fragment and the transaction is added to back stack, the expectation after a popBackStack() is to return to the previous fragment with its UI state intact. Activity backstack takes care of this expectation quite cleanly until a low-memory situation occurs. But in case of fragments, this isn’t the default behaviour. In a vanilla implementation, the replaced fragment’s view-hierarchy would get recreated upon returning back to it. Reason is that during a replace operation, all the destructive life-cycle methods get called till onDestroyView(), which wipes out the view-hierarcy. Upon returning back, all the constructive lifecycle methods right from onCreateView() get called, thus, recreating the view-hierarchy totally afresh. Reason for this flow is to keep ‘Fragments’ memory friendly. Without the view-hierarchy, a fragment is just a java object with a bunch of instance variables.

Continue reading

 

Session Management

This is the fifth part of a 6 posts series on Fragment oriented application architecture. In the previous post I talked about efficiently handling back button press inside fragment. In this part I am going to talk about session management in Fragment oriented application, by explaining integration of Facebook SDK.

(Sample application’s source code and README)

In a fragment oriented application, we can conveniently manage all session related code in the activity and all its fragments would utilise it. Facebook SDK is quite in sync with this approach. Implementation of Facebook session is closely bound to an activity. And then this session is accessible throughout the application. As has been discussed before, if an application requires to sign in from different portions of it, it will be way more convenient to have those portions as parts of the same activity. So that the authentication code need not be duplicated.

Continue reading

 

Handling back button press Inside Fragments

This is the fourth part of a 6 posts series on Fragment oriented application architecture. In the previous post I talked about Inter-Fragment Communication. In this part I am going discuss about elegantly handling back button press inside fragments in a fragment oriented application.

(Sample application’s source code and README)

Android devices have a hardware back button which normally serves the purpose of going back through the screens/actions stack. Callback to a back button press event is received in the foreground Activity (onBackPressed() event callback) which can be overridden and handled.

Continue reading

 

Inter-Fragment Communication

This is the third part of a 6 posts series on Fragment oriented application architecture. In the previous post I talked about Transaction BackStack and its management. In this part I am going to talk about Inter-Fragment Communication. It’s a general concept, not deeply linked to the context of this series.

(Sample application’s source code and README)

It’s a communication pattern over which fragments should talk to each other. Ideally, a fragment should never keep a reference of another fragment or even, in best case, of the specific parent activity. So, how would two fragments communicate? Consider the following scene.

Continue reading

 

Transaction BackStack and its management

This is second part of a 6 posts series. In the first post I talked around basics of fragment oriented architecture. From this post onwards, I’ll be talking about it’s implementation details.

(Sample application’s source code and README)

In this part I am going to talk about Transaction Backstack and few related methods that can be used frequently.
Transaction BackStack has often been misinterpreted as backstack of fragments. FragmentManager inside an activity deals with fragment-transactions rather than with fragments. An entry into this backstack is a ‘fragment-transaction’ which can be composed of one or more operations involving fragment(s). Reverting this would revert back all these operations together.

FragmentTransaction ft = getFragmentManager().beginTransaction();
ft.add(restId, fragmentA);
ft.replace(fragmentB);
ft.commit();

Above, is a single transaction clubbing multiple operations.

Continue reading

 

Advocating Fragment Oriented Applications in Android

This is a series of 6 blog posts which explains about Fragment Oriented Architecture in Android applications. In this first post, I’m going to explain what is Fragment Oriented Architecture and why shall one care. In subsequent posts I’m going to talk about following topics.

Continue reading

 

Compiling native libraries for Android L

Preparing your app for Android L ?

While using native executables in our existing Android apps we observed that those executables were no more working with Android L. We came to know that Android has introduced one more security feature starting from Android L i.e
Executable must be PIE (Position independent executable).

To compile a library adhering to above security feature you just need to follow these steps:

  1. Set following LDFLAGS or linker flags : -pie -fPIE
  2. Add --with-pic option while configuring the library.

Some libraries might use different configure options to compile the code with PIC (Position Independent Code) so to check all available configure options for PIC you can use this command:

./configure -h | grep -i pic

If there is no PIC option in configure script then you can try passing -fPIC option with your CFLAGS.

Now, compile the project (make, make install) and it should generate PIE.

To check if you’ve successfully generated a Position Independent Executable (PIE)

You can use “hardening-includes” package on Ubuntu or Debian.

Continue reading

 

Cross Compiling FFmpeg with x264 for Android

Recently we were working on a feature where we had to combine an image and audio to create a video on mobile devices. In iOS this can be done using AVAssetExportSessionthough – for detail see this link However, we could not find any native solution for this problem in Android.

FFmpeg is one such tool to tackle this problem but it is not available for Android officially. We tried few existing Android ports of FFmpeg but they were either outdated or didn’t work for us. So we planned to fold our sleeves and compile the library for Android.

Compiling libraries on Linux system is a fairly common task, download the source code of the library and run three commands:

./configure 
make 
make install

As we wanted to use the FFmpeg library on Android devices, we can’t just use the executable generated on the Linux machine directly because Android devices have different CPU architecture, different instruction sets and modified Linux kernel (OS). So we needed to cross compile FFmpeg library for Android

Cross Compilation ?

The process of building executable binaries on one machine, and running them on another machine when the CPU architecture or the Operating System are different is called “cross compilation”.

Continue reading

 

Expense Tracking Made Easy with Our Android Application – Expense Tracker

Most of us are oblivious of our spending behavior and more often than not end up asking questions like ‘How can I improve my spending habits’? Or ‘how can I hold back unwanted expenses’? Let’s accept it, mainstream population is unmindful of their spending behavior and typically end up overspending (of course some people claim to know where their money is going). It is difficult to fully dispute this claim, but there is a fair degree of skepticism. None of us is a human calculator after all (unless you are not using a traditional pen and paper approach for your book-keeping).

The truth is, without proper analysis we only have a vague sense of where our money goes and this where the real need of an expense tracking mechanism becomes essential.  Needless to say, not just any expense tracking application would do. It can be argued that there are many ways to track expenses and one should pick the one that suits the requirements. But at the same time the method should be hassle free and not cumbersome or time consuming. And there is no better way to be able to track your expense on your mobile while you are ‘On the Go’.

After having used a variety of Android applications for expense tracking and management, we were itching to develop our own version of an expense tracking and management app, as we felt there were many apps that lacked user friendly UI, ease of use, were over burdened with features, etc.

What we are able to achieve with our Android application is a simple, clutter free, intuitive yet powerful expense tracking application that addresses the need for monitoring daily expenses.

The application is out in the Android Marketplace and into the hands of many people with Android devices wanting an easy way to track and manage their expenses.

About Expense Tracker and Features

Expense tracking ‘On the Go’ becomes a whole lot easier with this easy to use, intuitive and simple daily expense management application. ‘Expense Tracker’ helps you to manage your money 7 days a week, 24 hours a day.

Expense Tracker Expense TrackerExpense Tracker

Just as the expenses do not stop, neither should money management. And with money being a limited commodity (for most of us), it is important to use it judiciously. ‘Expense Tracker’ is developed to help everyone who has the need for financial management and that includes everyone who indulges in economic activity of any nature.

Features:

1)    Set reminder for expense entries
2)    Track exp on daily, weekly, monthly and yearly basis
3)    Graphical representation
4)    Mark expense entries as favorite and later add it as an expense from favorite
5)    Take a picture of the expense receipt and save it for future reference
6)    Save expense as voice recording
7)    Log location of the expense automatically
8)    Date and time of the expense is logged automatically
9)    Expenses can be modified to a previous date

Application Link - https://market.android.com/details?id=com.vinsol.expensetracker

 

What every iphone developer ought to know about Google’s Android platform ?

I think Android is an undiscovered Gold mine for mobile app developers who want to build sustainable business.

1. Not just for smart phones : We are moving towards machines that will be somewhere between Smartphone, Netbook and PC. We have recently seen tremendous growth in netbooks. Freescale has announced that they are going to launch $100 netbooks based on Google’s Android operating system.

2. Android is Open Source - Let’s look at recent history of operating systems for desktops. We had Windows and then Linux and lately Ubuntu emerged and challenged the basic notion of people whose previous experience has been dealing mainly in proprietary product. We are going to see the same kind of polarity shift in mobile application with iphone being the major player with huge growth opportunity in open source system like Android.

3. Open Handset Alliance: There are 20+ members of Open Handset Alliance that are behind Android Operating System. HTC has just announced a keyboard-less phone based on Android. We should expect some more handsets coming out this year. I think its too early to assume that Android is  not so exciting or successful.

4.  Money – All the apps available in the Android Market have been free. This has prevented  developers from creating applications for the Android platform. Android Market is now accepting paid applications from US and UK developers. Unlike on the App Store for Apple’s iPhone, developers don’t need to get their products approved by Google or by service providers. With the Android Market, developers get 70 percent of revenue from each software purchase, with the remaining amount going to carriers . Google does not take a percentage but they use their own payment system , Google checkout.

I believe iphone is a great platform(and I love it) but we dont want to put all our eggs in one basket.