Android Programming Tutorials

(Romina) #1
No, Really Listening To Your Friends

Account l=new Account(user, password, callback);

poll(l);
accounts.put(callback, l);
}

public void removeAccount(IPostListener callback) {
accounts.remove(callback);
}
}
}

Extra Credit...............................................................................................


Here are some things you can try beyond those step-by-step instructions:



  • Switch to using a database as the storage mechanism for statuses,
    rather than RAM. The service can insert new statuses into the


database and keep the table trimmed to some maximum number of
statuses (to keep storage requirements down). The callback would

notify the activity that there were updates requiring a refresh of the
activity's CursorAdapter on the database. Consider using a preference

to allow the user to control the maximum number of statuses to
track.


  • Right now, when several timeline entries are added through one API


call (e.g., the initial poll), they are put in the list in the wrong order.
Change Patchy and PostMonitor to have them appear in the proper

order, no matter how many entries are retrieved in a single poll.



  • Have the background thread running only if there is one or more


registered listeners.



  • LocalBinder calls poll() upon registerAccount(), to force a timeline
    update right away. However, this is done on the main application


thread, which is a bad idea, since poll() involves network I/O.
Modify LocalBinder to use an AsyncTask for the initial call to poll().

200
Free download pdf