Things every new Android Developer should be aware of

Published / by glethien / Leave a Comment

Walking through the world you can see mobile devices everywhere and if you are a developer or want to become one, you may come to the conclusion that development for mobile devices seems to be a great idea. You are right! But first make sure you know the following things, which I think are essential for every android developer!

 

Basic understanding of Android Architecture

If you start working on a new platform you should at least read one or two articles about the platform. This applies to android too. You can start with this tutorial which will give you a basic understanding. From my point of view this should be more than enough to know. With this knowledge you are able to understand what is happening and why something works as it is. This leads to better source code and more stable apps!

Java

As you will use Java for developing your apps, you will need a good skillset in Java. If you do not feel secure using asynchrous thinks, listener and other basic Java funcionalities, you should read about basic Java topics and gain confidence, so you can focus on the android related things.

Android Studio

You have the possibility to choose between Android Studio and Eclipse as you IDE. I highly recommend using Android Studio! It’s based on IntelliJ and Google implenented a lot of nice features into Android Studio which will make your development much easier and enjoyable. Learn the shortcuts and where to find the important settings, files and make yourself known to the UI tools.

Activity and Fragment Lifecycle

Activites and Fragments will be your be your daily bread. Both of them have a slightly different lifecycle which you should know. The lifecycle is important to know when to load, when to unload or when to cancel open network connection as well as database handler. The official documentation for Android does have a very good description which you can read here. In short: When the system calls the onResume() you should open the database connection and when onPause() is called you should close the connection again (if you haven’t done before). This ensures that there is no leaked connection which can be abused.

Passing data between Fragments

There are a lot of ways to pass data between Fragments and I would say there are a lot of advantages and disadvantages for each method. Here is the one method I am using.

First I create the Fragement and in give it a static method.

public static MyFancyFragment newInstance(final DataModel model) { 
    MyFancyFragment instance = new MyFancyFragment ();
    instance.setArguments(new Bundle());
    instance.getArguments().putSerializable("DataModelField",model); 
    return instance;
 }

The other important part is to parse the serializable back into the DataModel and store it in the fragment.

public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    View view = super.onCreateView(R.layout.my_fancy_fragment_layout, inflater, container, savedInstanceState);
    dataMode = (DataModel) getArguments().getSerializable("DataModelField");
    return view;
}

That’s it. If you want to create a new instance of the fragment, just call newInstance and pass the DataModel as parameter into the fragment. Your data will be available after onCreateView is called. As this is part of the lifecycle, this method is called for sure! This isn’t the best way or the worst way, it is just one way to do it. I recommend to take a look at other approaches and adapt the one which fits most for you.

dp vs pixels

Pixels are the actual pixel on the screen. Pretty straight forward. Problem is that nearly every device has a different resolution. Using pixel it will be impossible to create a resolution independent layout. Therefore Android introduces dp. dp stands for Density-independent Pixels and is a fictional unit for creating UIs. 1dp is roughly 1px on a 160 dpi screen. For any other screen the actual amout of pixel for 1 dp is calculated by the device.

Debugging your app

Android proves the serveral methods for debugging. You have the full log in AndroidStudio, you get crash reports in you GooglePlay Console after you’ve released you app, but most important is to write your own log outputs. Luckily this is very easy as you just need to call the static method

Log.d(TAG, "onCreate() No saved state available");

You can set a specific TAG, which is maybe something like “network”, “database”, “fancyShit” or everything else. After that just add a filter for the logcat and you will only see messages with the specific tag. In addition AndroidStudio provides methods for CPU usage, GPU usage and finding memory leaks. You should make yourself familiar with those tools! It will save you a lot of time.

Googles Plans

Currently the process in the world of mobility is very fast, so as a professional android developer you should know what the next fancy stuff is and when it will be available, so you can make use of it. For starters you can checkout the android twitter account or the android developers Youtube channel. Once a year Google is host of the Google IO, a annual developer conference with focus on sessions and lesson about developing for mobile and web with Google.

Material Design guidelinbttes

Users expect a specific behaviour of an app and where to find what. Google tried to make a standart for the layout. I advise you to follow those guidelines, as it will improve the user experience. A coworker once said, that you must assume that the human cursor has at least a 1cm diameter. Image having tiny buttons close together… Most likely you will never hit the right one and getting frustrated. You can find the material design guidelines here

Most likely: you wont be successfull

For each of you the most important point: YOU MAY WON’T BE SUCCESSFULL

This sounds harsh but this might be the only truth you will need. Currently there are more than 2 million apps! Don’t expect to publish one or two apps and land the next hit! This CAN happen and I would be very happy for you if it does, but don’t relay on it. Maybe you idea isn’t even new. Just take a look at how many clones of CandyCrush you can find on Google Play Store. With more than 2 million apps available, it’s very hard to find your app! Do it just for you! If you really want to have some more downloads, think about spending money into marketing your app!

=1

Day in a life: Android Developer

Published / by glethien / Leave a Comment

Let us talk about what I did for the last year. After college I’ve started working as Android Consultant, which had it’s ups and downs. This is what I want to talk about today and how a normal day looked like.

A normal day for the last year

As being a consultant normally includes a lot of travelling I will devide this into two subsections. The first for the time I was at our office and the other section about travelling.

For the whole time I was assigned to the same project. This project includes travelling every second weeks. I am not allowed to talk about the project or for which company we’ve worked, but I will try to give a general overview about how such a project works.

We’ve used SCRUM for organizing our daily work. SCRUM is an agile framework for managing software projects which short, normally two weeks, iterations. The big advantage is that the customer or project owner can change his mind about nearly every detail every two weeks. This two weeks iteration is called SPRINT. Each sprint contains several tasks. The amount of tasks depends on the velocity of the team and the complexity for each single task. We need to keep this in mind for later. For more details about SCRUM, just ask Google or Wikipedia. One little and important thing: Each day the team has a short meeting about the progress. In this meeting you are just telling the team what you did yesterday, what you are planning for the current day and if you have any problems.

Office days

Normally, during the days in our office, I’ve started the day which slack. Slack was our main tool for communication. As I started working early, I was also the first person to leave work. So I started with reading the messages and mails when I was gone. Depending on the problem this took up to 10 minutes each day. After this I’ve logged in to the VPN and took a look at our SCRUM board. The board contains the tasks for the sprint and you can see which developer is working on which tasks. It also provides a basic idea about the progress for each task.

If I was done with my tasks and there were unfinished tasks left, I started working on a new tasks or told my coworkers that I have some capacity left and could help them, if needed. A task was done when a short “Definition of Done” was completed. This means that the Unit tests are green, the merge request was successful and at least one developer took a short look at your code, regarding style, bugs, smells and so on. After all this was completed the task had to be burned, which means that we presented our work to the customer. If he was statisfied with our work, he approved the task otherwise we had to do some refactoring. We called this process burning. Depending on the complexity of a task this could take about one hour.

Slack was present nearly every minute. Asking coworkers, the product owner or sometimes the SCRUM Master is a very important part of being a developer, regardless for which platform or programming language! We used slack also for discussing how to implement things, asking questions about parts of the code you don’t know and where to find something.

Each week when I was in the office contained the grooming. Grooming is a relativly long meeting with the analysts in which the developer team is sizing the tasks for the upcoming sprint.

The days in the office were pretty straight forward: Searching for a free place to work, setting up notebook, putting on headphones and starting the daily routine describes above.

Travelling week

As a sprint is two weeks long, we need to plan the next sprint every two weeks. As the customer was part of this meeting and the planning is very boring aswell as time consuming, we all meet in person.

For me this means a lot of travelling and a lot of time in the air. Our first meeting was at 10:30 am which means I had to get up at 4:30 am, starting with my morning routine (sometimes a bit slower…) and leaving at 5:40 heading to th airport. At the airport go throu security check, waiting in line at the gate and finally getting into the plane. The flight was about 50 minutes, then leaving the plane at roughly 9:00 am. I personally made use of the public transportation system as much as possible but other colleges prefered to get to the customer by taxi.

The first meeting was a presentation of the work done last sprint for the customer. Each workbench (iOS and Android) presented their work in a 15 – 20 minutes timeslot. Normally the customer is asking questions about the layout, behaviour or other little things afterwards.

When the presentation was done, we meet in private without the customer for our retrosepctive. We talked about the good things and the bad things, problems of the last sprint and wishes for the upcoming sprint. In average I was able to be at the hotel at 16:30 pm. Most of the time I was really tired and exhausted so I wasn’t in the mood to leave the hotel. Most of the time I went to the next grocery store and bought myself dinner. Later when I got used to this routine I started running and afterwards enjoying my dinner on the bed and watching TV. I’ve seen a lot of different hotels which are close to the customer and most of the time it was not possible to watch Netflix or something similar.

The next day was breakfast between 7.30 am and 8:00 am and heading back to the customers HQ for Planning 1 and Planning 2. So a day full of sitting around and talking with others. This may sounds interessting but I can tell you, noone (not even the customer) was enjoying this. I was long, boring and full with senseless discussions. If you have some people with economical background in your team, I feel sorry for you… At roughly 4 pm I was heading back to the airport. Same airport routine as the day before. It was very exhausting so when I was back home at 9pm (planned) I got directly into my bed. Most of the time the organization at german airports is very bad, so the planned time of departure was nearly never correct. Planes got cancelled or delayed one or two hours, which means spending more time at the airport, without getting much overtime.

 

Conclusion

The part about programming and development was very cool with nerdy coworkes. The other things like wasting my lifetime at airports, in hotels or in senseless and boring meetings made me rethink my descision about being a consultant. On the one hand you get into very different projects with different technology, on the other hand you will loose a lot of your sparetime. I think this is just a personal descision. I am happy and exited to start my new inhouse job next month!

=3

Android Splash Screen

Published / by glethien / Leave a Comment

Recently I’ve came across a minior discussion about Splash Screen in Android.

We talked about the usefulness of those splash screens. Some want to use them to display the company logo or app logo, so the user has to stare several seconds on the logo. If the screen stays for 3 secs and the user opens the app 3 times a day, this makes 9 seconds of waiting or 35 secs a week. If you have 1 million users, your users will wait for 35000000 secs or 583333 minutes or  9722 hours A WEEK! Just let this huge numbers sink in…

What a waste of time!

On the other hand Google advocates using splash screens. You can find it here in the material design guidelines. All Google apps like Youtube, Mail or others using splash screens! But they only let the user wait the minimal time necessary for the app to load! Not a second longer.

 

Implement a splash screen

 

So at first you will need a simple layout in xml which defines your splash screen. A minimal one with the app logo centered is enough! This could look like this:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:paddingBottom="@dimen/activity_vertical_margin"
    android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    android:orientation="vertical"
    tools:context=".SplashActivity"
    android:gravity="center_vertical|center_horizontal">

    <ImageView
        android:layout_width="200dp"
        android:layout_height="200dp"
        android:id="@+id/imageView"
        android:layout_centerHorizontal="true"
        android:layout_alignParentBottom="false"
        android:background="@drawable/logo" />
</LinearLayout>

This will create an layout with a 200dp squared logo centered. Don’t overload the screen with text, logo and other stuff! In the best case this screen will stay less than a second and the user don’t have enough time to read everything!

In Java you just load your app and then proceed to the next activity as soon as possible

protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_splash);

        // Here do some bootup stuff, but nothing long loading.
        Intent intent = new Intent(this, MainActivity.class);
        startActivity(intent);
        finish();
}

And that’s it. You may request the permissions before calling the intent, but there is no more magic. With this you have an activity as splash screen which only stays for the minimal needed time and not wasting your users time.

=7

Changes – bye bye Youtube

Published / by glethien / Leave a Comment

Welcome to my first post! Nice to see you!

In early 2012 I’ve started my Youtube Channel with the same name as this blog. During the past years I was able to get around 750 subscribers. This is a pretty awesome number for the specific and german content I was creating. If you already know my channel, you may have noticed that during the last month I haven’t release a lot of videos. This is accounted for the fact that I’ve lost the motivation for creating content which has a horrible visibility on Youtube.

Currently my videos are about 15 min average length. The viewer retention for my whole channel is very bad… just 25% or roughly 4 minutes and this is for a tutorial. Means the average viewer skips about 75% of my tutorial and I doubt that in this 25% you can learn, understand and follow what I was trying to explain. The last video with more than 200 views is now 8 month old. Every other video released afterwards has less than 200 views. I know for real, that this blog won’t get much attention at all, but I hope that the few people coming here, get more than 25% of my content.

My brother pointed out that videos on Youtube may are the from platform for teaching programming. This was the point where I tought about quitting Youtube and starting something different. And here you are. This is what is new and different. My old Channel was in german, I’ve decided to write my blog in english. The main reason for this is: challenging myself and get a greater audience!

About this new blog

Don’t be afraid of textwalls. I will keep creating videos but now short clips for emphasizing the written word. You will also get a lot of sourcecode. Okay guess this was obvious at this point… another blog about programming can’t go without a lot of sourcecode.

My main content will be about snippets, tutorials and problems I’ve encountering in my daily life as android developer. Sometimes I will write about things which are currently in my mind and related to being a nerd. Currently I have no idea what the future of this blog looks like, but we will see…

=5