Android – Basic testing with unit test, android test and roboguice, robolectric, mockito

Bugs are always the most annoyed things for developer. It’s a dream (which never comes true) that a software runs without any problem at client’s site. There are always some points that developers have to improve after deployment. The more time developers invest for testing, the better the software is and the less annoyance developers have. I made many examples of Android development which are small apps and illustrate how a point of interest works. As a demo, I didn’t care too much about if there is a bug in app code because it isn’t a complete application. However if we want to make something that can be sold to customers, we have to be sure that our software should be reliable as it could be. Therefore in this post I would like to discuss some simple basic tests in Android development. We will learn how to write a logical unit test with JUnit, an integration unit test with test classes from Android and some advanced test cases with Roboguice, Robolectric and Mockito.

Continue reading Android – Basic testing with unit test, android test and roboguice, robolectric, mockito

Android – Sqlite database with ContentProvider and LoaderManager

If you follow my previous posts, you may already know that we discussed how to make an application with database in Android before in Android, Dependency Injection (IOC) with roboguice and MVVM (Model-View-ViewModel) pattern. Although the main topic in that article relates to Dependency Injection but we had also a working example which fully supports all CRUD actions for Sqlite database. However, in practice, it shouldn’t work like that because the synchronous read/write actions will block the user interface and your apps will freeze. When your database grows over time, the query time gets longer and you app will completely freeze during the query get executed. Therefore, in this post, I would like to make a sample for illustrating how a database application can work in asynchronous mode.

Continue reading Android – Sqlite database with ContentProvider and LoaderManager

Android – Show images from Flickr with ImageGridView

Flickr is a wonderful image hosting and video hosting of Yahoo. With a free account, you can get a disk space up to 1 TB for uploading and sharing your photos as well as videos. In this post, I would like to make a small demo showing how we can consume the Flickr’s REST web service and display public images of an album on Android phone. The images could be shown either in thumbnail mode or medium mode. The example app is just a proof of concept, you have to improve it when you want to build a same one in practice because I just don’t care about optimizing resources (memory) in source code. You will also ‘learn’ how to implement a singleton pattern (in entire app) with roboguice. That means, small example, interesting use cases.

Continue reading Android – Show images from Flickr with ImageGridView

Android – Upload files to ASP.NET Web API service

In previous posts, I showed you how to get/post data to ASP.NET Web API service. However, until now, I only used JSON for communicating between server and client and what about for binary data? For example, uploading files to ASP.NET Web API? How should the controller work and which kind of HTTP request/HTTP format should the Android client send to server? In this blog post, I will show you a simple way to transfer binary data. In the demo, I have 2 components : web service and android client. Unlike the other post, for this one, unfortunately, I don’t have any sample web service (online over internet) for you to test. I don’t own any windows server (neither VPS nor dedicated server :() therefore I can’t host any web service allowing file uploading.

Continue reading Android – Upload files to ASP.NET Web API service

Android – Media player and ASP.NET Web Api

Let’s start with a question. When was the last time you played a song offline at your computer? For me, It’s long,loong,looong… time ago. Since the boom of music websites, I just choose one provider, create my favorite playlist and listen to music online. I don’t have any CD or .mp3 song at my local computer anymore, except that there are still a lot of songs in my Ipod but I don’t know where he is right now 😕 and that’s … bad. If something wrong happens with the website, my song will go with the wind. Moreover nowadays, in the dangerous internet, I doubt all of apps (if they are harmful) and consider a lot every time I install an app on my Android smartphone. So I always try to write the app or software myself if they aren’t complex. For this case, for my favorite songs, I decide to write a very simple media player connecting to my web service, playing my own song and I don’t have to worry anymore about the problem mentioned above. That’s is the concept. Next, I would like to show my media player works, if you want to improve it, go on!

Continue reading Android – Media player and ASP.NET Web Api

Android, Dependency Injection (IOC) with roboguice and MVVM (Model-View-ViewModel) pattern

If you’re working with .NET, maybe you’re already familiar with the concepts of dependency injection and MVVM (Model-View-ViewModel) pattern. Some of popular dependency injection containers for .NET are Castle Windsor, Ninject or Unity… They are all good frameworks, it just depends on which you prefer. For example, I use Castle Windsor at company and Ninject at home so that I can understand and use both of frameworks. It’s just the matter of favorite. The MVVM pattern was introduced years ago when WPF came to market. This pattern makes use of data binding structure of WPF and helps programmer to separate the view completely from logic layer. For more details about this pattern you can read some articles on my site about MVVM. Today, I will discuss again about these concepts, however not for .NET application, but I would like to show how we can apply these concepts into Android app. The example I use in this post is a De-De-Dictionary app. In this app, I can add German vocabulary with his explanation (also in German :)) through a user interface or look up for a vocabulary. Nothing special than a real dictionary book.

Continue reading Android, Dependency Injection (IOC) with roboguice and MVVM (Model-View-ViewModel) pattern