Making a layout

Open app/res/layout/activity_main.xml. You’ll see the layout designer, with a “Hello World!” text at the center of a device screen. The text is an example of a so-called view. Technically, a view is just a class that extends View and draws something on the screen. A view whose purpose is to display other views is called a view group. The classic way of creating Android layouts is to use various ViewGroup classes, such as LinearLayout, FrameLayout and so on....

March 26, 2018

Save the date!

So do we put the deadline in outState and consider ourselves done? Well, we want to keep the deadline even if the entire phone is turned off, don’t we? Instead, we’ll use SharedPreferences. This is essentially a glorified way to save small amounts of data in key:value format on disk. SharedPreferences survive practically everything except a factory reset (and even then we can choose to have it backed up by Google)....

March 26, 2018

Setting and showing a deadline

Let’s be honest here: dealing with date arithmetic is a pain, and working with Java or Kotlin does not exactly make things easier. In real apps, use JodaTime or JSR-310 to deal with dates. To keep things simple, we’ll use the old java.util.Date class you know from TDT4100 (“the Java course”) and a very dirty hack to calculate the number of hours left. Android Studio will complain, if you find it annoying just add @SuppressWarnings("deprecation") at the top of our class....

March 26, 2018

The anatomy of an Android project

In the project overview on the left-hand side, you’ll see quite a few folders and files. Here’s an overview: res/layout/activity_main.xml Here’s the layout for our main activity! We’ll get back to this in a moment. res/mipmap/ic_launcher This is our app’s icon, which will be displayed on the home screen (back in Android 1.x, this was called the “launcher”). It comes in many different sizes. Which size is used depends on the phone....

March 26, 2018

When things go sideways – understanding lifecycle

Open the app, set a deadline, and turn the phone sideways so it switches to landscape mode. What happened?? Just turning the phone sideways made the app forget the deadline! Clearly this must be a bug in Android!? To understand what happens, we need to understand that mobile apps work differently from other apps. As Apple puts it: “Your app can be interrupted at any time. When an interruption occurs, your app should save the current state quickly and precisely so people can seamlessly continue where they left off when they return....

March 26, 2018

Hello Android Studio!

Android Studio is where all Android development happens. It contains everything you need to develop, run, test and deploy Android apps. If you have worked with IntelliJ before, you’ll probably want to know that Android Studio actually is a fork of IntelliJ IDEA – so almost all keyboard shortcuts and menus are the same. If you’re new to IntelliJ and Studio, you need to learn two shortcuts right now: Ctrl + Shift + A: search for anything in any menu....

March 26, 2018