android tips & tricks - boosting your productivity
DESCRIPTION
After several years of making android applications, I've collected a bunch of tips and techniques to improve the development process. These are going from discovering non-standard tools, knowing better your IDE, using fundamental and some uncommon libraries and other stuff. This presentation is aimed for those in the beginner and intermediate levels but I'm sure advanced developers will learn a couple a things as wellTRANSCRIPT
Tips&Tricks
Boosting your productivity
Fernando García Bernal @fegabe (twi$er, linkedin, github…)
¿Quién soy? • ¿Dónde? Malagueño en Barcelona • ¿Qué? Freelance Android/iOS. +3 años experiencia móvil
Contenido
• Mejorar entorno desarrollo • Librerías fundamentales • Códigos fuente • Patrones de diseño • Snippets
Mejorar entorno desarrollo
android x86
www.android-‐x86.org
adb (Android Debug Bridge) • adb devices • adb kill-‐server && adb start-‐server • adb push / pull
Recuperar apk (necesario root!) $ adb pull /data/app/com.facebook.katana-‐1.apk
• adb install / uninstall • adb shell
Acceso SQLite $ adb shell; $ sqlite3
• Conexión wireless con disposiKvo: adbWireless
Proxy • Charles Proxy
• ¿Cómo? • Configurar Android (si lo permite) • Usar aplicación (si Kenes móvil rooteado) • Por código:
DefaultHttpClient httpclient = new DefaultHttpClient();HttpHost proxy = new HttpHost("1.2.3.4", 8080);httpclient.getParams().setParameter(ConnRoutePNames.DEFAULT_PROXY, proxy);
Colored logcat
Permite personaliza la salida editando el fichero ~/.logcat-‐color h$ps://github.com/marshall/logcat-‐color.git
Re-‐aprender Eclipse • Técnica milenaria de vista dual para edición de interfaces
• Otros • Refactors • expresiones regulares • Shortcuts: desplazar líneas
Librerías fundamentales
ActionBarSherlock
Jake
h$ps://github.com/JakeWharton/AcKonBarSherlock Implementación AcKonBar design pa$ern
HoloEverywhere
Christophe
h$ps://github.com/ChristopheVersieux/HoloEverywhere.git Holo Theme de Android 4.0 para 1.6+
Roboguice
h$p://code.google.com/p/roboguice/ Reduce el código + Inyección de dependencias
@ContentView(R.layout.main)class RoboWay extends RoboActivity { @InjectView(R.id.name) TextView name; @InjectView(R.id.thumbnail) ImageView thumbnail; @InjectResource(R.drawable.icon) Drawable icon; @InjectResource(R.string.app_name) String myName; @Inject LocationManager loc; public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); name.setText( "Hello, " + myName ); } }
Reporte de Crashes
Kevin
Envío automá^co de crashes h$p://code.google.com/p/acra/
@ReportsCrashes(formKey = ”apiKey") public class MyApplication extends Application {
Mejor visualización h$p://www.bugsense.com/
Analíticas
Roger
App Annie www.appannie.com
Códigos fuente de referencia
Repositorios • Código fuente de android
h$ps://github.com/android
• Aplicación Github h$ps://github.com/github/android
• Librerías Square
h$ps://github.com/square h$p://slideshare.net/burkeeric/android-‐app-‐anatomy
• commonsware.com
h$ps://github.com/commonsguy
Y si no… descompilar • h$p://code.google.com/p/android-‐apktool • h$p://code.google.com/p/dex2jar
./apktool d -d apks/$apkname.apk apps/$apknamesh dex2jar.sh $apkname.apkUnzip ${apkname}_dex2jar.jar –d $apkname/srcjad/jad -o -r -sjava -d$apkname/src “$apkname/src/**/*.class"
Interfaces awesómicas
No seas delincuente
Android niceties h$p://androidniceKes.tumblr.com/
Snippets
Comunicación entre Activities
• Si los parámetros son clases personalizadas: • Si son pequeños, Serializable • Si no, implementar Parcelable (si es una imagen pasar filepath)
public static Intent getCallingIntent(Context ctx, String url, String title) {
Intent i = new Intent(ctx, BrowserActivity.class);
i.putExtra(EXTRAS_OPEN_URL, url); i.putExtra(EXTRAS_WEB_TITLE, title); return i; }
Custom Logger
public class DebugLog{ public final static boolean DEBUG = true; public static void log(String message) { if (DEBUG) { StackTraceElement stack = Thread.currentThread().getStackTrace()[3]; String fullCN = stack.getClassName(); String className = fullCN.substring(fullClassName.lastIndexOf(".") + 1);
String methodName = stack.getMethodName(); int lineNumber = stack.getLineNumber(); Log.d(className + "." + methodName + "():" + lineNumber, message); } }}
¡Gracias! @fegabe