Categories
Android

Handling the multi-touch in a view

In this post you find a full example about how to

  • extend a view to draw, in this case, a circle where you touch the screen
  • implement a listener on a view to handle the multi-touch
Categories
Android

Displaying notifications and progress bar from an instance of AsyncTask

The AsyncTask class is used to perform background tasks and it might be useful to show notifications and progress bars to alert the user.
In this post I write an example where I create two AsyncTask instances showing a startup notification, a progress bar and a notification of completed task

Categories
Android

How to display an icon in the preferences

In the Android preferences you can put different types of controls: check box, edit box, list,…, but none of these displays an icon (see Settings).
Usually a preference consists of two lines, the title and the summary, and after you have clicked you get a dialog box where you can select the chosen item, as you can see in the two pictures below.

Categories
Android

How to implement Up Navigation

In this example you can see how to implement the Up Navigation, i.e. the option to go back to a previous activity using the button in the upper left of the action bar.
The previous activity can be a fixed activity or an activity determined at runtime.

Categories
Android

Replacing a Fragment in a Tab Layout with an ActionBar

In the post Tab Layout in Android with ActionBar and Fragment the fragments can’t be replaced later, in this post I write the changes in order to replace the first fragment of the first tab with a third fragment using a button at runtime.

Categories
Android

The services in Android

A service is a task running in the background to perform actions without a user interface and they are used to perform long running operations with a significant use of resources by avoiding delays in the user experience.
The services belong to one or both of the following categories:

  • started: the service is launched using the the method startService()
  • bound: the service is launched using the the method bindService() and the components of the application that has launched the service can communicate with the same service
Categories
Android

Passing an object from an Activity to another

The method startActivity(Intent intent) of the class Activity allows you to call a second activity specified using the argument Intent.
You can associate primitive data or primitive data array to the argument Intent and then the second Activity can access them, you can also pass objects of type String using methods of the class Bundle like put*().
In this post I show an example to pass a more complex object between an Activity and another.

Categories
Android

Javadoc in Eclipse and Android

In Eclipse launching javadoc from menu (Project -> generate javadoc…) if you get the errors:

  • error: package android… does not exist
  • error: cannot find symbol
Categories
Android

Getting the Context inside a Fragment

It is very easy to get the Context inside an Activity:

  • with the getApplicationContext() method
  • using only “this” because the Activity class extends the Context class

But you can’t use any of these two methods inside a Fragment and you have to replace them respectively with:

  • getActivity().getApplicationContext()
  • getActivity()

I often do this replacement when I use code written for an Activity, but that I must use in a Fragment.

Categories
Android

Script for creating Android Icons

Just another tool to create Android icons, such as gimp-android-xdpi.
You can find at Script for creating Android Icons or at GIMP script for creating Android icons at once.