HTTP Client. Alternative to Apache's HTTPClient and java.net.HttpUrlConnection. • Can be used with Retrofit. • From their site: Perseveres when the network is troublesome square.github.io/okhttp
downloading and caching library. • Automatic memory and disk caching. • Mostly one-liners to load a remote image into an ImageView. • Supports: resizing, cropping, placeholders. • Can use OkHttp square.github.io/picasso
65K DEX methods limit Unable to execute dex: method ID not in [0, 0xffff]: 65536 Conversion to Dalvik format failed: Unable to execute dex: method ID not in [0, 0xffff]: 65536 • Choose third-party libraries wisely • Use Proguard if you can’t avoid it
on demand Not class MyActivity extends Activity { private Service service; @Override public void onCreate(Bundle savedInstanceState) { ... service = restAdapter.create(LifebitService.class); } @OnClick(R.id.submit) public void onButtonClick(Button button) { List<Bit> bits = service.getBits(); // Do something with bits } }
on demand Not Not class MyActivity extends Activity { private Service service; ! Service getService() { if (service == null) { service = restAdapter.create(LifebitService.class); } return service; } ! @OnClick(R.id.submit) public void onButtonClick(Button button) { List<Bit> bits = getService().getBits(); // Do something with bits } }
ignore exceptions! try { List<Bit> bits = service.getBits(); ... } catch (APIException e) { // Something terrible has happened // but I am too lazy to handle this exception. // So f*ck you users! ! // Logging is not considered handling an exception! Log.d(getClass().getName(), e.getMessage()); }
ignore exceptions! try { List<Bit> bits = service.getBits(); ... } catch (APIException e) { // If you are sure that the message is safe for the end user: showDialog(e.getMessage()); } Inform the user
ignore exceptions! Crash that motherf*cker try { List<Bit> bits = service.getBits(); ... } catch (APIException e) { // I am pretty sure that an exception will never happen, // but just in case: throw new RuntimeException(e); }
Free weekly newsletter for the latest Android dev news, tutorials, articles, etc. • android-arsenal.com: List of free and paid Android libraries • github.com/futurice/android-best-practices: Android dev best practices