Android Development Tips


Software is getting more complex by the day. Nowadays, when you want to write a simple Android app you need the Android framework and SDK (software development kit) and maybe an IDE (integrated development environment) like Android Studio or Eclipse. There is a lot packed into the Android Framework and SDK that beginners will find it difficult to digest.

 

 

Therefore, the goal of this post is to go over some tips to the challenges I faced when I started Android development.


 

Permission System

The Android system has a permission system that any Android app must follow. For example, if an app needs to access files on a device, the user must give the app permission(s) to do so. Without proper permission(s) the app cannot proceed.

 

You as the developer must specify the permissions that your app needs in the Android Manifest. The Android Manifest provides the Android system with an overview of your app. A simple manifest provides the Activities, Services, and Permission(s) within your app. Depending on which version(s) of Android you want to support, your app may need to support multiple permission system standards.

 

Marshmallow and Above (6.0+)

With Android Marshmallow and above, a new permission system was introduced along with other new features. The new permission system requires an app to request for permission when it needs it (during runtime). What this means is that you must programmatically request for permission(s) where your app needs it and to safeguard against permission(s) being denied by the user. You will also need to include all the permissions your app needs in the manifest. Unlike Android Lollipop (5.x) and below you do not have the assurance that your users have given your app all the permissions that it needs at installation.

 

I have a post about Android Marshmallow permission system and asking the user for permission during runtime that you should definitely check out. Also, I have a post about other new features added to Android Marshmallow if you are interested.

 

Lollipop and Below

With Android Lollipop and below, permissions are not a big concern for the app developers. This is because, in order to install the app, the user must give all permissions that the app requires. As a developer, this means you have the peace of mind that your app will not crash due to permission issues in most cases. Do note that after giving permissions and installing the app, the user can go through the settings to manually revoke some permissions. Also, it is still necessary to include all the permissions that your app requires in the manifest.

 

Application File Location

By default, the Android API (application programming interface) provides you with a simple way to manage files within your app’s internal storage. It is not necessary to request permission to read and write from your app’s internal storage (this may change with newer versions of Android). Your app’s internal storage is accessible only by your app. This becomes a problem if you want to create a file that is accessible by other apps.

 

In order to create a file that is accessible for other apps, your app must have permission to write to external storage. External storage is from the perspective of the app, therefore anywhere outside of the app’s internal storage is considered “external.” This is important because the internal memory partition that is accessible by other apps has an alias “sdcard.” This is not to be confused with the physical microSD card that you might have in an Android device. A physical microSD card is considered a storage by the Android system.

 

Debugging

Debugging your app is something that is unavoidable. At one point or another, you will find yourself fixing bugs in your app. There are some tools out there to help you make debugging easier.

 

Android Debug Bridge

The Android Debug Bridge (ADB) provides you with tons of features to test your application. Probably one of the most useful feature you will find with ADB is the LogCat system, which allows you to print out debugging messages from your app. You can use ADB wired or wireless with some extra setup.

 

Wired

If you are using Android Studio, it already has ADB LogCat system support. When you upload your app to your testing device via USB, the LogCat system automatically start. As long as your testing device is connected, the LogCat system will work. What about when you need to occupy the USB port of your testing device?

 

Wireless

It is possible for you to initiate a wireless session of ADB to your testing device through WiFi. To do this, you will need to use the terminal to invoke ADB and establish a wireless connection to the device through its IP address. The Android documentation about ADB provides thorough step-by-step instructions on how to do this.

 

Printing to UI TextView

Maybe you are stuck in a situation where you cannot use wired or wireless ADB debugging. In such a case, you can use the UI of your app as a debugging console. Create a TextView and append all your debugging messages there. You might want to preserve space, so it is best to wrap your TextView in a ScollView. Here is a way to implement a fast scrolling text view:

 

        <ScrollView android:layout_width="fill_parent" 
                    android:layout_height="wrap_content" 
                    android:scrollbars="vertical" 
                    android:fillViewport="true" 
                    android:layout_weight="0.5" 
                    android:id="@+id/scroller_text_view">

                    <TextView android:layout_width="fill_parent" 
                              android:layout_height="fill_parent" 
                              android:id="@+id/debug_text_view" 
                              android:hint="Debug Messages"/>

        </ScrollView>

 

If you found this post helpful, share it with others so they can benefit too.

 

What are some of the challenges you faced when you began developing for Android? What was giving you the most problems?

 

Leave a comment or send me an email steven@brightdevelopers.com. To stay in touch, follow me on Twitter.


About Steven To

Steven To is a software developer that specializes in mobile development with a background in computer engineering. Beyond his passion for software development, he also has an interest in Virtual Reality, Augmented Reality, Artificial Intelligence, Personal Development, and Personal Finance. If he is not writing software, then he is out learning something new.