Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Evolución Android (v3.0, DevFest Tarragona 2014)

Rubén Serrano
October 30, 2014
34

Evolución Android (v3.0, DevFest Tarragona 2014)

Rubén Serrano

October 30, 2014
Tweet

Transcript

  1. 1. El Origen de las Especies 2. Camino a la

    Extinción 3. Evolución Agenda
  2. public class Application extends android.app.Application {
 private static Gson gson;

    private Map<Long, Integer> mRoles; private Session mSession; private File mCacheDir; private NotificationManager mNotificationManager; private int mNumberNotifications; ! public static Session getSession() {
 return instance.mSession;
 }
 public static String getGCMToken() {
 AccountManager am = AccountManager.get(Application.getContext());
 return am.getUserData(Application.getSession().getUser(), AccountAuthenticator.GCM_TOKEN);
 }
 
 public static File getCacheDirectory() {
 return instance.mCacheDir;
 }
  3. The android.app.Application class The android.app.Application is a base class for

    those who need to maintain global application state. It can be accessed via getApplication() from any Activity or Service. It has a couple of life-cycle methods and will be instantiated by Android automatically if your register it in AndroidManifest.xml. http://goo.gl/skj7dA
  4. A Singleton class There are advantages to using a static

    Singleton […] But, the life cycle of a static is not well under your control; so to abide by the life-cycle model, the application class should initiate and tear down these static objects in the onCreate() and onTerminate() methods of the Application Class http://goo.gl/skj7dA
  5. private static class ViewHolder {
 public TextView textView;
 public ImageView

    imageView;
 } ! @Override
 public View getView(int position, View convertView, ViewGroup parent) {
 View view = convertView;
 ViewHolder viewHolder;
 if (view == null) {
 view = inflater.inflate(R.layout.item, parent, false);
 viewHolder = new ViewHolder();
 viewHolder.textView = (TextView) view.findViewById(R.id.text);
 viewHolder.imageView = (ImageView) view.findViewById(R.id.image);
 view.setTag(viewHolder);
 }
 viewHolder = (ViewHolder) view.getTag();
 viewHolder.textView.setText("Random string");
 viewHolder.imageView.setBackgroundColor(R.color.black);
 return view;
 } ViewHolder
  6. @Override
 public View getView(int position, View convertView, ViewGroup parent) {


    View view = convertView;
 if (view == null) {
 view = inflater.inflate(R.layout.item, parent, false);
 }
 ((TextView) view.findViewById(R.id.text)).setText(“Random string");
 ((ImageView) view.findViewById(R.id.image)).setBackgroundColor(R.color.black);
 return view;
 } No Holder
  7. Juguemos… • Descargar datos de un servidor • Parser JSON

    • Guardar datos en la BBDD • Recuperar datos de la BBDD • Mostrar datos en la pantalla
  8. • Descargar datos de un servidor • Parser JSON •

    Guardar datos en la BBDD • Recuperar datos de la BBDD • Mostrar datos en la pantalla Juguemos…
  9. “Una Activity para gobernarlos a todos; una Activity para encontrarlos;

    una Activity para atraerlos a todos y atarlos a las tinieblas” - El Señor de los Fragments
  10. LoaderCallbacks<Cursor> callback = new LoaderCallbacks<Cursor>() {
 @Override
 public Loader<Cursor> onCreateLoader(int

    id, Bundle args) {
 return new CursorLoader(context, uri, null, null, null, null);
 }
 
 @Override
 public void onLoadFinished(Loader<Cursor> loader, Cursor data) { adapter.swapCursor(data);
 }
 
 @Override
 public void onLoaderReset(Loader<Cursor> loader) {
 
 }
 }; LoaderCallbacks
  11. It is not the strongest of the species that survives,

    nor the most intelligent, but rather the one most adaptable to change. Charles Darwin
  12. It is not the strongest of the species that survives,

    nor the most intelligent, but rather the one most adaptable to change. Charles Darwin