PreferenceActivity Basics

SDK Version: 
The PreferenceActivity class is a very easy way to create a standard looking settings screen for any application.

Minimal coding is required. The values are stored in SharedPreferences automatically by the PreferenceActivity.

The list of settings, default values, keys to stored under are defined in a very simple xml file.

The xml file should be located in res/xml/ directory and look like something like this:

  1. <?xml version="1.0" encoding="utf-8"?>
  2. <PreferenceScreen xmlns:android=""
  3.         android:title="Settings">
  5.         <EditTextPreference android:title="Name"
  6.                 android:inputType="text" android:summary="Set your login name here"
  7.                 android:key="name" android:persistent="true" android:defaultValue=""></EditTextPreference>
  9.         <EditTextPreference android:title="Password"

Remote control your android

SDK Version: 
In this tutorial I'll show you a way to remote control your android device via Wifi, Lan, Internet or Usb.
You'll need 2 applications installed on a rooted device, and another client software installed on your pc or another phone.
First, go to market, and install and open this application:

Then you can install this Vnc Server application:


How to use static variables in activities

SDK Version: 

As previously described in Leaving an Android application, when you exit an app by pressing back button its resources are not completely destroyed immediately.

I would like to explain a concrete mistake I met multiple times, in connection with this behavior, which is easy to commit, if you forget this.

Root your phone without using an usb cable

SDK Version: 

A few weeks ago ztomi had a tutorial about ADB wireless. You propably already have your favourite way of rooting your phone (superoneclick etc), but what if you don't want or can't use the usb port of your phone?

How to create context menu

SDK Version: 

There are two main methods that you must implement to get this thing work.
First of all, implement and override the onCreateContextMenu():

  1. @Override
  2.         public void onCreateContextMenu(ContextMenu menu, View v,
  3.                         ContextMenuInfo menuInfo) {
  4.                 super.onCreateContextMenu(menu, v, menuInfo);
  5.                 menu.setHeaderTitle("Choose an option");
  6.                 menu.add(0, v.getId(), 0, "Add to favorites");
  7.                 menu.add(0, v.getId(), 0, "See details");
  8.         }

How to create android applications for tablets?

SDK Version: 

With the new 2.3 SDK, we get the opportunity to develop android for tablets. (At least, with the Galaxy Tab Addon).

When starting a new tablet emulator, first we need to set the "Scale display to real size" option. This helps to set the tablet's size, to our screen size. In my case, it's 1440x900px.


Handling old data in new app versions

SDK Version: 

When you release a newer version of your application, on update the android system identifies from the package name and version number, that the user has an older version installed. During updating not all data of the previous version is overwritten, databases, preferences, previously downloaded/created files on sdcard or internal storage remain unchanged. If there are any incompatibility with the old version of these, is must be taken care of.

First of all, files on the external storage can be lost or corrupted due to many other reasons, so version incompatibility is just one more reason to check those files before using them.
However the internal storage is theoretically not modified by external sources, if there are version incompatibilities, you have to check the state of this files too.

Android 2.3 Gingerbread SDK review and bugs

SDK Version: 

gingerbreadIt's been over a week since gingerbread came out, i've been using the updated sdk since day one.

Here is a little review about it from the developers point of view (it's not as sweet as the name suggests...).

Gradient dividers

SDK Version: 

Today I’m going to show you an easy way to create gradient backgrounds in your applications.

Create an xml file in drawable directory and modify like this:

  1. <?xml version="1.0" encoding="utf-8"?>
  2. <shape xmlns:android=""
  3.         android:shape="rectangle">
  4.         <gradient
  5.          android:startColor="#FF0000"
  6.          android:endColor="#00FF00"
  7.          android:angle="90" />
  8. </shape>

This code snippet generate a divider with gradients that fade from green to red.

After that you can use that such a drawable for layout background.

  1. <?xml version="1.0" encoding="utf-8"?>
  2. <LinearLayout xmlns:android=""
  3.     android:orientation="vertical"
  4.     android:layout_width="fill_parent"
  5.     android:layout_height="fill_parent"
  6.     android:background="@drawable/gradientcolors">
  8. </LinearLayout>

How to store large amount of data

SDK Version: 

The internal storage of an android device is very limited, so if your application downloads or somehow generates a large amount of data to store, you should save it on the external storage, the sd card. Even 1mb of data takes much space compared to the whole internal capacity on most of the current devices. The sd card has a bigger magnitude, and it is even expandable.

Even when storing data on the sd card you should limit the space your application can use up. For example if you cache images for an application you should track the usage the images and when the sum size of them exceeds a given limit, delete the the oldest used one.

When developing for API Level 8 (2.2) the directory get by the getExternalFilesDir() method can be used for storing files. Files stored here will be automatically deleted when the application is uninstalled.


Syndicate content