Warning: "continue" targeting switch is equivalent to "break". Did you mean to use "continue 2"? in /home/choste/public_html/press/wp-content/plugins/papercite/papercite.php on line 413

Warning: "continue" targeting switch is equivalent to "break". Did you mean to use "continue 2"? in /home/choste/public_html/press/wp-content/themes/suffusion/functions/media.php on line 669

Warning: "continue" targeting switch is equivalent to "break". Did you mean to use "continue 2"? in /home/choste/public_html/press/wp-content/themes/suffusion/functions/media.php on line 674

Warning: "continue" targeting switch is equivalent to "break". Did you mean to use "continue 2"? in /home/choste/public_html/press/wp-content/themes/suffusion/functions/media.php on line 687

Warning: "continue" targeting switch is equivalent to "break". Did you mean to use "continue 2"? in /home/choste/public_html/press/wp-content/themes/suffusion/functions/media.php on line 692

Warning: "continue" targeting switch is equivalent to "break". Did you mean to use "continue 2"? in /home/choste/public_html/press/wp-content/themes/suffusion/functions/media.php on line 697
Coding » UnRulyRecursion
Warning: Declaration of Suffusion_MM_Walker::start_el(&$output, $item, $depth, $args) should be compatible with Walker_Nav_Menu::start_el(&$output, $item, $depth = 0, $args = NULL, $id = 0) in /home/choste/public_html/press/wp-content/themes/suffusion/library/suffusion-walkers.php on line 17
Feb 142014
 

Warning: sizeof(): Parameter must be an array or an object that implements Countable in /home/choste/public_html/press/wp-content/plugins/papercite/papercite.php on line 205

Howdy hackers,

If you play around with Android, here’s a quick tip I found today:

Parcelable vs Serializable

april 18, 2013

When starting on Android, we all learn that we cannot just pass object references to activities and fragments, we have to put those in an Intent / Bundle.

Looking at the api, we realize that we have two options, we can either make our objects Parcelable orSerializable. As Java developers, we already know of the Serializable mechanism, so why bother with Parcelable?

To answer this, lets take a look at both approaches.

Serializable, the Master of Simplicity

1
2
3
4
5
6
7
8
9
10
11
12
// access modifiers, accessors and constructors omitted for brevity
public class SerializableDeveloper implements Serializable
    String name;
    int yearsOfExperience;
    List<Skill> skillSet;
    float favoriteFloat;
    static class Skill implements Serializable {
        String name;
        boolean programmingRelated;
    }
}

The beauty of serializable is that you only need to implement the Serializable interface on a class and its children. It is a marker interface, meaning that there is no method to implement, Java will simply do its best effort to serialize it efficiently.

The problem with this approach is that reflection is used and it is a slow process. This mechanism also tends to create a lot of temporary objects and cause quite a bit of garbage collection.

Parcelable, the Speed King

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
// access modifiers, accessors and regular constructors ommited for brevity
class ParcelableDeveloper implements Parcelable {
    String name;
    int yearsOfExperience;
    List<Skill> skillSet;
    float favoriteFloat;
    ParcelableDeveloper(Parcel in) {
        this.name = in.readString();
        this.yearsOfExperience = in.readInt();
        this.skillSet = new ArrayList<Skill>();
        in.readTypedList(skillSet, Skill.CREATOR);
        this.favoriteFloat = in.readFloat();
    }
    void writeToParcel(Parcel dest, int flags) {
        dest.writeString(name);
        dest.writeInt(yearsOfExperience);
        dest.writeTypedList(skillSet);
        dest.writeFloat(favoriteFloat);
    }
    int describeContents() {
        return 0;
    }
    static final Parcelable.Creator<ParcelableDeveloper> CREATOR
            = new Parcelable.Creator<ParcelableDeveloper>() {
        ParcelableDeveloper createFromParcel(Parcel in) {
            return new ParcelableDeveloper(in);
        }
        ParcelableDeveloper[] newArray(int size) {
            return new ParcelableDeveloper[size];
        }
    };
    static class Skill implements Parcelable {
        String name;
        boolean programmingRelated;
        Skill(Parcel in) {
            this.name = in.readString();
            this.programmingRelated = (in.readInt() == 1);
        }
        @Override
        void writeToParcel(Parcel dest, int flags) {
            dest.writeString(name);
            dest.writeInt(programmingRelated ? 1 : 0);
        }
        static final Parcelable.Creator<Skill> CREATOR
            = new Parcelable.Creator<Skill>() {
            Skill createFromParcel(Parcel in) {
                return new Skill(in);
            }
            Skill[] newArray(int size) {
                return new Skill[size];
            }
        };
        @Override
        int describeContents() {
            return 0;
        }
    }
}

According to google engineers, this code will run significantly faster. One of the reasons for this is that we are being explicit about the serialization process instead of using reflection to infer it. It also stands to reason that the code has been heavily optimized for this purpose.

However, it is obvious here that implementing Parcelable is not free. There is a significant amount of boilerplate code and it makes the classes harder to read and maintain.

Speed Tests

Of course, we want to know how much faster Parcelable is.

The methodology

  • Mimic the process of passing object to an activity by putting an object in a bundle and callingBundle#writeToParcel(Parcel, int) and then fetching it back
  • Run this in a loop 1000 times
  • Do an average on 10 separate runs to account for memory allocation, other apps using the cpu, etc
  • The object under test are the SerializableDeveloper and the ParcelableDeveloper shown above
  • Test on multiple devices – android versions
    • LG Nexus 4 – Android 4.2.2
    • Samsung Nexus 10 – Android 4.2.2
    • HTC Desire Z – Android 2.3.3

The results

parcelable vs serializable

Nexus 10

Serializable: 1.0004ms,  Parcelable: 0.0850ms – 10.16x improvement.

Nexus 4

Serializable: 1.8539ms – Parcelable: 0.1824ms – 11.80x improvement.

Desire Z

Serializable: 5.1224ms – Parcelable: 0.2938ms – 17.36x improvement.

There you have it: Parcelable is more than 10x faster than Serializable! It is also interesting to note that even on a Nexus 10, a pretty simple object can take about 1 millisecond to go through a full serialize/deserialize cycle.

The Bottom Line

If you want to be a good citizen, take the extra time to implement Parcelable since it will perform 10 times faster and use less resources.

However, in most cases, the slowness of Serializable won’t be noticeable. Feel free to use it  but  remember that serialization is an expensive operation so keep it to a minimum.

If you are trying to pass a list with thousands of serialized objects, it is possible that the whole process will take more than a second. It can make transitions or rotation from portrait to lanscape feel very sluggish.

source: http://www.developerphil.com/parcelable-vs-serializable/
Apr 102013
 

The Git mad App-A-Thon is back, and so am I (Taylor), along with continuing partner Larry, and new addition Tamil! This year’s contest will include GT WebDev as well, so we are looking forward to a bigger, better contest with more apps and more prizes!

Last year’s app-a-thon was a great experience, and as a team and individually we learned a great deal. The 14 hour ordeal took quite a toll on us, but we did stick it out to the end and had a working prototype to show off!

This year we are planning to do even better!

To start, take a look at last year’s research post here. It contains lots of background and useful information whether in the learning, design, or building phase of an app.

Next, if you haven’t yet, DEFINITELY read all the way through the Android training course. I can’t stress this enough, there is extremely important information in that.

-Android Training Course link

After that, take a browse through the API Guides / App Components section of the Android Dev website. This is where I currently am, and it covers material that is slightly higher level.

-Android App Components link

Lastly, for anything else Android related, Vogella has lots of good tutorials such as the one below which covers ListViews and Adapters. That site will definitely be a good resource if we get stuck.

-Vogella ListView Tutorial link

Get PSYCHED!


edit: 4/15/2013

Yo, App-A-Thon SP’13 is coming up soon. If we do the inventory app, which is looking more and more likely, I think we will employ some/all of these resources:

– Meteor Framework link – This will be used to rapidly develop a rich webapp with a fluid backend database.

– MongoDB link – This is the database that Meteor is based on. We’ll have to do some hand-waving to go back and forth with SQLite (the android db).

– Handlebars link – This is a minimalist js framework that provides HTML templating. It is the preferred template-r for Meteor. We can use this to lay out the page, and have full and mobile sites.

Read up on these and how to use them, because they are going to help make our app kick-butt!


edit: 4/18/2013

T-1 day on the countdown, here are some more links that I have been looking at in preparation for this event. A lot of them have to do with getting up to snuff with meteor!

A good thing to note is that the Meteor team likes answering questions on Stack Overflow ( Tag: meteor ) and on IRC ( link )

– ( link ) First resource, Meteor official Documentation. Has great information above the nitty-gritty as well

– ( link ) A team at CMU working with Meteor during a Hack-A-Thon

– ( link ) Collection of learning resources for Meteor

– ( link ) Another Hack-a-Thon experience, but this time information from the point of view of learning it on the fly

– ( link ) Third Party Fundamentals and Best Practices

– ( link ) Caveats of Javascript

– ( link ) Mozilla Dev Network JavaScript Guide (for da n00bs)

 

 

 

 

Nov 292012
 

First Things First

Get your computer set up to develop properly

1. Get the Android SDK: http://developer.android.com/sdk/index.html

This step can either be completed with the first link, which includes a large bundle of everything you’ll need, or, use the drop-down menus to find other options (for example, if you already have an IDE). Android seems to prefer Eclipse.

2. Install Eclipse Plugin: http://developer.android.com/sdk/installing/installing-adt.html

3. Configure; download a few platforms, I grabbed 4.2 (Jellybean), and 2.2 (Froyo)

Had some trouble with this in Win8, needed to allow more permissions for the folder where it is holding the images and whatnot.

 4. Install Subclipse: http://subclipse.tigris.org/

I installed the 1.8.x Release of Subclipse, which corresponds to Subversion 1.7.x Awesome, now get developing! What, you need more? Read on then!

Notable Links

Main Developer Website – http://developer.android.com/index.html Training Home Page – http://developer.android.com/training/index.html Reference Home Page – http://developer.android.com/reference/packages.html Obligatory Wikipedia Links – Main: http://en.wikipedia.org/wiki/Android_(operating_system) – Version History: http://en.wikipedia.org/wiki/Android_version_history (Useful for figuring out which Android version number goes with which Android Dessert Code Name)

Tutorial – http://www.vogella.com/articles/Android/article.html

 

Android Application Activity Life Cycle

An important thing to note (and indeed, something central to Android and all apps),  is that the Activity Life Cycle is super important. If you pay no attention to this, your app may not start, may lose data, and even act sporadically. Therefore, study the following diagram, as well as the life cycle as whole.

Note (from O’Reilly): “It is possible for a paused activity to be destroyed as well. For that reason, it is better to do important work, such as saving unsaved data, en route to a paused state rather than a destroyed state.”
 

Here is a set of Lecture Slides that was published online: AndroidLifeCycle

Activity Life Cycle

Or perhaps this illustration from the Reference section will appeal to you better.

Activity Life Cycle

If you prefer O’Reilly (owl), here is a link to an excerpt from Learning Android, which explains the Activity Life Cycle: http://answers.oreilly.com/topic/2692-android-programming-understanding-the-activity-life-cycle/

Documentation and Reference

Reference

Main Page: http://developer.android.com/reference/packages.html Activity Page: http://developer.android.com/reference/android/app/Activity.html

Lessons and Training

Getting Started: http://developer.android.com/training/index.html Building Your First App: http://developer.android.com/training/basics/firstapp/index.html Managing the Activity Lifecycle: http://developer.android.com/training/basics/activity-lifecycle/index.html Invoking Google Applications with Intents: http://developer.android.com/guide/appendix/g-app-intents.html

 

Random Collection

http://wptrafficanalyzer.in/blog/implementing-horizontal-view-swiping-using-viewpager-and-fragmentpageradapter-in-android/

http://developer.android.com/reference/android/hardware/Camera.html

http://www.vogella.com/articles/AndroidCamera/article.html

http://mobile.tutsplus.com/tutorials/android/android-layout/

Nov 292012
 

UnRulyRecursion evangelists Taylor and Sterling will be participating in the GIT MAD Fall 2012 App-a-Thon in collaboration with Larry. This will be an exciting rush of mobile application development (stretching from Friday, Nov. 30 at 6pm to Saturday, Dec. 1 at 12pm) that will be judged at the end. We are raring to go, with a great idea for an app, willing and capable coders, and prizes looming.

If you are interested in following or seeing our progress, the repo and possibly TRAC will be added below.

Stay tuned to hear how it goes and see the app we build! The event’s webpage is here ( link ).