Langsung ke konten utama

Postingan

Menampilkan postingan dengan label tutorial

Image loading with Glide

Image loading seems like an easy task at the first glance but as every task, it has its' own caveats. First of all, you probably want to do this asynchronously because you don't want to flood your main thread with that kind of tasks. Then, you want to cache images so you don't load them every time your activity of fragment resumes. You need to handle error cases when the network is not available or server is sending you garbage or doesn't send anything at all. If you don't do this it will definitely harm the user-experience. After all, you probably need to do some pre-processing steps before showing the image to the user such as cropping, resizing, reversing etc. Also, it would be convenient to have an easy way to set an image in an ImageView. You may ask: "Why do you think that you know what I need and want?". The answer is that you're not alone. Android developers already made tons of apps that use pictures from the network. And what happens when man...

Introduction to Firebase Database for Android

I've already written a post about Firebase and its' features but features highlighted in the post are additional to the core functionality of Firebase. What is this core functionality? Well, this is the thing that Firebase started from. It's Realtime Database . A real-time database is, basically, the database that can effectively store dynamic data. By dynamic, I mean data that is constantly changing for example stocks prices. Firebase Database So Firebase has its' own built-in real-time database which you can use as a backend for your app. Let's consider the structure of this database. First of all, it's worth to mention that this database is not relational and doesn't use tables as you might expect. It uses JavaScript Object Notation (JSON)  to store the data so it's kinda "object-oriented" database.  I think that this it an advantage at least for developers because JSON, in my opinion, is easier to understand than relational tables if you...

What is Content Provider

Today I will continue my "What is *Android component*" series and tell you about one of the essentials parts of an Android application a content provider. Previous posts from this series: What is Activity What is Fragment The problem First of all, let's consider the problem that this component is meant to solve. It's often useful for applications to retrieve data from other apps on the smartphone. Many pre-installed Android apps have the data that can improve the user experience of other apps.  For example, phone book has information about the people that are probably your friends and it can be used by social networking app like LinkedIn to connect with someone you know in this social network. User dictionary has information that can help users type faster by providing them with the most used words when they use a custom keyboard. So, it would be convenient to have some tool that can share those kinds of data. Something that would provide a consistent interface acros...

What is Fragment

The concept of a fragment is tied very tight with the concept of an activity. And if you don't understand clearly what activity is I encourage you to read last week's post first and then return to fragments. Also, here's the post that will help you to get a nice overview of basic Android classes such as Context, Activity, Fragment, Thread etc. What is the problem With the growth of popularity of Android system more and more developers started to pay attention to it. More and more apps were developed for Android and it entailed more and more complexity in these apps. In particular, this complexity was growing in activities and layouts. Possible solutions First of all, developers wanted something that would be reusable in several activities. And this, as I think, gave a birth to ActivityGroup .  As the documentation says it's A screen that contains and runs multiple embedded activities which seems like a bit overhead. In this implementation, every activity has i...

What is Activity

Hi, today we will talk about one of the basal things in Android application an Activity. How to understand an Activity Activity is the basis of your application and entry point as well. From the user side, it's a single focused thing that user can do while interacting with your application. Most of the Activities interact with the user and take care of creating a window for your UI.  Also, using multiple Activities to represent various tasks helps a programmer to make app's code less complex and easier to maintain.  Activities can be used as fullscreen or floating windows and as a part of another activity (in an ActivityGroup , note that it's deprecated since API 13). Activity insights Firs of all to start an activity you should define it in your manifest using <activity>  tag inside <application> . Like this: <manifest> <application> <activity android:name=".MyActivity" /> </application> </manifest > Every class...

Tutorial: Flexible Space With Image Action Bar

Android Support Library Android Support Library provides many useful features for android developers and doing it with backward-compatibility in mind. Watch this video where Ian Lake explain why it's so good ( it's just me or his smile looks terrifying? Leave your thoughts in the comment section). As you may guess we'll use design part of this library, actually a small part of the design part. To be able to use it in your project you should add a gradle dependency. compile 'com.android.support:design:23.3.0' Flexible Space With Image is a scrolling technique that was presented as a part of the material design and Android Support Design Library makes it really easy to implement one and also makes it backward-compatible so you don't need to write a code mess to support it on each API. We can achieve this effect with very small amount of java code using XML primarily. We’ll use CoordinatorLayout , AppBarLayout , and CollapsingToolbarLayout . CoordinatorLayout a...

Tutorial: Android ListView With Custom Adapter

There are so many apps utilizing ListView in Android. Your feed in a social network, your tasks in a to-do app, even your mail in your favorite email app stored in a ListView. Basically, ListView is a container for a collection of items that can be represented as an array. You should be able to get any item from a collection by its index and get the size of an underlying collection. Also, it would be nice to be able to add new elements to your collection unless you want it to be constant. In my opinion, ArrayList  fits this definition perfectly. In ArrayAdapter , they use List as an underlying collection, though, but in some implementations of it ( LinkedList  for example) get operation is linear of index you pass to it, so it can be bad for performance. But it's not a reason to reject ArrayAdapter, just be careful with what implementation you pass to it. Custom List Adapter ArrayAdapter by default adapts only strings to TextViews, but we want someth...