We’ve just released 1.5 Preview 1 to the canary channel!
Android Studio 1.5 Preview 1 Available
We’ve just released 1.5 Preview 1 to the canary channel!
This repository showcases and compares different architectural patterns that can be used to build Android apps. The exact same sample app is built three times using the following approaches:
Standard Android: traditional approach with layouts, Activities/Fragments and Model.
MVP: Model View Presenter.
MVVM: Model View ViewModel with data binding.
The sample app displays a list of GitHub public repositories for a given username. Tapping on one of them will open a repository details screen, where more information about the repo can be found. This screen also shows information about the owner of the repository.
/app directoy contains the implementation that follows the traditional standard Android approach. This is a couple of layout files, two Activities and the model. The model is exactly the same for the three implementations and it contains:
User and a retrofit service (
With this approach, Activities are in charge of calling the
GithubService, processing the data and updating the views. They act kind of like a controller in MVC but with some extra responsibilities that should be part of the view. The problem with this standard architecture is that Activities and Fragments can become quite large and very difficult to tests. Hence why I didn’t write any unit test for this case.
/app-mvp you will find the sample app implemented following this pattern. When using mvp, Activities and Fragments become part of the view layer and they delegate most of the work to presenters. Each Activity has a matching presenter that handles accessing the model via the
GithubService. They also notify the Activities when the data is ready to display. Unit testing presenters becomes very easy by mocking the view layer (Activities).
This pattern has recently started to gain popularity due to the release of the data binding library. You will find the implementation in
/app-mvvm. In this case, ViewModels retrieve data from the model when requested from the view via data binding. With this pattern, Activities and Fragments become very lightweight. Moreover, writting unit tests becomes easier because the ViewModels are decoupled form the view.
Convert Java String to Binary
public class CodeSnippets
public static StringBuilder getBinary(String value)
byte bytes = value.getBytes();
StringBuilder binary = new StringBuilder();
for (byte b : bytes)
int val = b;
for (int i = 0; i < 8; i++)
binary.append((val & 128) == 0 ? 0 : 1);
val <<= 1;
Today we are releasing the 1.4 update to the Android Studio stable release channel. Most of the work and enhancements for Android Studio 1.4 are under the hood. However we have a handful of new features that we hope you enjoy and integrate into your workflow.
Nexus 6P, Nexus 5X and Pixel C Everything you need to know
Here is one important question Android developers ask while making apps: “How can I do ________ in Android?”
The following are versions of this question that we came across recently:
This course is a collection of such questions and their answers.
By the end of this course you will have mastered the ability to implement new Android features by reading a blog or article — this is a critical skill possessed by professional Android developers. As a result, you will also be able to use several User Interface components — like Toggle Buttons, Menus, Grid View and many more — that are central to making functional and delightful Android apps.
To support the growing number of developers who are building richer apps and games on Google Play, we are increasing theAPK file size limit to 100MB from 50MB. This means developers can publish APKs up to 100MB in size, and users will see a warning only when the app exceeds the 100MB quota and makes use of Expansion Files. The default update setting for users will continue to be to auto-updating apps over Wi-Fi only, enabling users to access higher quality apps and games while conserving their data usage.
Even though you can make your app bigger, it doesn’t always mean you should. Remember to keep in mind the following factors:
In this quick tip, we take a brief look at the popular Android image library, Picasso. It’s a simple and practical library created and maintained by Square. It is great for working with images in your Android projects.
Picasso is an image library for Android. It’s created and maintained by Square, and caters to image loading and processing. It simplifies the process of displaying images from external locations. In many cases only a few lines of code is required to implement this neat library.
Picasso shines for displaying remote images. The library handles every stage of the process, from the initial HTTP request to the caching of the image. This can be quite verbose when writing code to perform these actions yourself. In this quick tip, we look at a few common use cases.
If you’re using Android Studio, then you can add
to the build.gradle file in the dependency section.
Create a new project in your IDE of choice. Make sure to select a blank Activity if you’re using Android Studio.
Open the layout file for the main Activity. We need to add an
ImageView to the layout. It doesn’t need to be fancy. The following code snippet shows you what I mean.
Navigate to the main Activity file. Add the following code block to the onCreate method.
ImageView imageView = (ImageView) findViewById(R.id.imageView);
In the first line, we get a reference to the ImageView instance in the layout file. We then load an image into the image view using the Picasso library. We first specify the context by calling with and passing in the context. We then call the load method and supply it with the location of the image, a URL in this case. Finally, we tell Picasso where it should display the image when it’s fetched by calling into and pass in the imageView object.
Your IDE will ask you to import the Picasso library. However, to do this manually add the following import statement at the top of the Activity class.
For Picasso to do its work, make sure to add
<uses-permission android:name="android.permission.INTERNET" /> to your project’s manifest.
That’s pretty much it. If you build and run the application, you should see the image load on the screen.
Picasso has much more tricks up its sleeve. In the following example, we use Picasso to fetch a remote image and resize it before displaying it in an image view.
Picasso also supports transformations, such as rotation. In the next code snippet, we fetch a remote image and rotate it 180 degrees before displaying it in an image view.
If your application relies on remote assets, then it’s important to add a fallback in the form of a placeholder image. The placeholder image is shown immediately and replaced by the remote image when Picasso has finished fetching it.
Picasso supports two types of placeholder images. We already saw how the
placeholder method works, but there’s also an
error method that accepts a placeholder image. Picasso will try to download the remote image three times and display the error placeholder image if it was unable to fetch the remote asset.
Note that you can combine the
error methods as shown in the following code block.
With Picasso being so simple to use, it’s definitely worth thirty minutes of your time. If you’re creating an app that frequently loads images, then Picasso could well make your life that little bit simpler.
The Google Maps Android API can serve a static image as a ‘lite mode’ map.
A lite mode map is a bitmap image of a map at a specified location and zoom level. Lite mode supports all of the map types (normal, hybrid, satellite, terrain) and a subset of the functionality supplied by the full API. Lite mode is useful when you want to provide a number of maps in a stream, or a map that is too small to support meaningful interaction.
Users viewing the map cannot zoom or pan the map. Icons on the map give users access to viewing the map in the Google Maps mobile app and requesting directions.