The world of open source libraries and tools is vast for Android developers. Writing apps using solely Android SDK is impractical. Libraries can help you in many ways. They can speed up your development, save you creating boilerplate code and dealing with platform fragmentation, simplify your code and make it more readable and maintainable. In the talk I’m showing how several truly useful libraries can help a developer.
Presented at MobCon Europe 2017.
22. Dagger 2
public class MainActivity extends AppCompatActivity {
@Inject SimpleProvider mSimpleProvider;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
((MyApplication) getApplication()).getAppComponent().inject(this);
// and now we can use mSimpleProvider
}
}
28. OkHttp
• an efficient HTTP client for Android and Java
• requests can be easily customized
• support for HTTP/2
• connection pooling
• transparent GZIP
• response caching
29. OkHttp
OkHttpClient client = new OkHttpClient();
Request request = new Request.Builder()
.url(url)
.build();
Response response = client.newCall(request).execute();
return response.body().string();
33. Stetho
• network inspection
• database inspection
• view hierarchy
• dumpapp system allowing custom plugins
• command-line interface for communication with the plugins
34.
35. Stetho
public class MyApplication extends Application {
@Override
public void onCreate() {
super.onCreate();
Stetho.initializeWithDefaults(this);
}
}
44. “How can I notify that class?“
“There has to be some way without refactoring the whole
thing!”
45. Event bus
• for communication between decoupled parts of an app
• EventBus
46. EventBus
• events
• subscribers
• register and unregister
• post events
public static class MessageEvent { /* fields if needed */ }
@Subscribe(threadMode = ThreadMode.MAIN)
public void onMessageEvent(MessageEvent event) {/* handle event */};
EventBus.getDefault().register(this);
EventBus.getDefault().unregister(this);
EventBus.getDefault().post(new MessageEvent());
47. “How do I get the data from the server?”
“And I have to combine couple of sources.”
48. RxJava
• general Java library
• reactive programming
• push concept
• composable data flow
49. RxJava
• useful for simple async processing
• async composition
• offers simple chaining of operations on data
• eliminates callback hell
50. RxJava
• works well with Retrofit
• can completely replace event bus libraries
• hard to learn
• RxJava 1 vs. RxJava 2
• they will coexist for some time