Just moozing

Before you can check your notes, you must make them…

Android and RESTfull API

leave a comment »

android-logoLast weekend, I created my first android app. It was a native java app, that connected to my RESTful API example.

 Getting started

As mentioned, this was my first android restand_screenshotapp. It wasn’t that difficult, but I had some confusion along the way.

I used Android studio. That was a good choice. It seems very complete with source completion, debug options and all the thing you would expect from a modern IDE.

After creating a simple hello world application, it was time to look at the emulators. That would have trivial also, if I had enough space on /tmp. I have approx. 1 GB, and I needed around 2 GB – when I realized what the problem was, I was able to do a “mount –bind …” to have android studio save stuff on a partition with enough space.

There was other suggestion, like telling java to use a different path for the temporary files, but they didn’t work for me.

I got the initial app running, without doing any actual java coding.

 

Doing GUI

On big conclusion, when it came to the GUI, was that you want to use linearlayout instead of the relativelayout (which is default). Relative stuff is perhaps good when you know what you are doing and want to do it for multiple devices – I don’t what I am doing and are doing it for my phone, so linearlayout was the way to go.

With linerlayout (vertical), you have rows in which you put your elements. And nesting linearlayouts (horizontal) makes it even more useful. This resembles what I have done with wxWidgets.

 

Doing connections

Since this is a client for a RESTful API, we need to do http connections. I went with the okhttp module.

It was mainly copy’n’paste, but we met the same quirk as with the JavaScript implementation, where the http connections must be made in a separate thread from the “main” thread. The solution is asynchronous calls as implemented as an AsyncTask (Yes, some refactoring might be in order…)

 

 Success!

Combining the RESTful API example from previous, some java magic, android GUI and some help – it works. See the readme file for how to use it.
The github repository is here. Feel free to fork it.

 

 

Advertisements

Written by moozing

November 3, 2016 at 12:00

Posted in Tech

Tagged with , ,

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: