Realtime + Android Apps




Aravind Krishnaswamy
www.arg0s.in
@twitortat

Hello


Hands-on Entrepreneur and Tech Executive.
Now: Building Musiguru & Singr at Levitum.
Past: Multiple startups. One IPO. One exit.
Android + iOS + Python.
Volunteered @ Droidcon `11, `12 &`13.
And ♥ Goa!

Whom this talk may benefit

Beginner level Android developers
Students looking to hack an app for fun
Small teams looking to build apps quickly
Developers targeting multi device users
Those building finance/biz apps
Game developers
 Social & collaborative apps



App - Stage I


App - Stage II


App - Stage III


Boilerplate, boilerplate


All the little things

Model state maintained in SQLite
Synchronized with the server
Approaches include No-SQL databases in sync
Older app versions end up with different models
Complexity of keeping multiple devices in sync
Duplication of code and business logic
Web + iPhone + Android?


This is when you go..


Dammit. 
All I really want to do 
is just build my frickin' app.


Enter BaaS Options

Parse
Stackmob
Kinvey
Firebase
Pusher
PubNub


Why BaaS

  • Up and running immediately.
  • No backend dev or dev ops costs.
  • Plans are cheap 
    • Until you get big (good problem to have!)
  • The data is yours 
    • Export when you want. Rebuild custom stack.



#1 reason they matter?

You get to *focus* on your app

We've all seen this one.




Is this really the answer?



Why Firebase

  • Cloud Storage
  • Synchronize data in real time
  • Greater app responsiveness
  • Great for apps where 
    • multi player games
    • collaborative social features
    • live interaction
    • data changes frequently (finance)

Firebase Setup


As simple as creating a reference
Firebase ref = new Firebase("https://nitrodroid.firebaseIO-demo.com");

Managing Parents & Children
Firebase childRef = ref.child("users"); 
// This is equivalent to: Firebase childRef = new Firebase("https://nitrodroid.firebaseIO-demo.com/users");

Firebase parentRef = childRef.getParent(); // parentRef and sampleChatRef now point to the same location.

Model Data

Writes
Map<String, Object> toSet = new HashMap<String, Object>();toSet.put("first", "arg0s"); toSet.put("last", "moi"); nameRef.setValue(toSet);
Completion Callbacks
 dataRef.setValue("Nitro", new Firebase.CompletionListener() {

    @Override
    public void onComplete(FirebaseError error) {
        if (error != null) {
            System.err.println("Data could not be saved: " + error.getMessage());
        } else {
            System.out.println("Data saved successfully.");
        }
    }

});

Controller

Async callbacks whenever data changes

Writes are local, then get synced

Attempts eventual consistency

Receives snapshots

What's the big deal?


Callbacks happen even if data changed on *other* devices.

Data updates & events are *incredibly* fast



What does this mean to you?

Caveats

  • Needs to be online at initial load - currently WIP
  • Tighter MVC bindings are still evolving
    • Already available for web (angular, ember)

Ergo...

Demo




A Simple NitroDroid Chat App
Powered by Firebase

Say Hello @ NitroChat

 
-> http://tinyurl.com/nitrodroid <-

QR Code

-> http://tinyurl.com/nitrodroid <-

Open Q & A



Thanks for listening!



@twitortat

www.arg0s.in


github.com/arg0s/nitrochat https://slid.es/arg0s/realtime-android-apps

Realtime + Android Apps

By Aravind Krishnaswamy

Realtime + Android Apps

Infuse real time into your Android apps

  • 3,138