Eclipse and memory

Eclipse is known for being slow and lagging, if you don’t have enough RAM in your computer. But I first realized how big an issue this was, when I upgraded my computer from 4 to 16GB RAM. After tweaking my eclipse.ini, it was really running smoothly, all the way through. Well, it still takes a little time to start it up, and initialize the various plugins, but when it is started, there is no more lag at all.

Upgrading the computer wasn’t all. I had to tweak the Eclipse configuration as well, to use more memory. I did that by assigning 2048MB RAM to Eclipse, instead of the default 384MB. My eclipse.ini memory settings then looks like this:

--launcher.XXMaxPermSize
512m
-vmargs
-Xms512m
-Xmx2048m

So, as RAM prices are very low these days, it certainly pays back to invest in an upgrade. Eclipse has never been so nice to work with as now.

You can read more about the eclipse.ini file at http://wiki.eclipse.org/Eclipse.ini

Posted in Android Eclipse by Kasper. No Comments

EditText in ListView hides behind keyboard

A problem I came across was that when I have an EditText control as the last element of a ListView, it would hide behind the soft keyboard. Not the first time the EditText is activated, but when hiding the keyboard by pressing the Back button, and clicking the EditText again, it would be hidden behind the keyboard.

This was only a problem if windowSoftInputMode was set to adjustPan. Setting this to adjustResize would display the EditText correctly every time.

I fixed this by subclassing EditText, and clearing focus when back-button is pressed.

import android.content.Context;
import android.util.AttributeSet;
import android.view.KeyEvent;
import android.widget.EditText;

public class PanningEditText extends EditText {

  public PanningEditText(Context context, AttributeSet attrSet) {
    super(context, attrSet);
  }

  @Override
  public boolean onKeyPreIme(int keyCode, KeyEvent keyEvent)
  {
    if(keyCode == KeyEvent.KEYCODE_BACK)
    {
      clearFocus();
    }
    return super.onKeyPreIme(keyCode, event);
  }
}
Posted in General by Kasper. 1 Comment

Android: Unknown device when debugging your app on your device

This is a problem that very often occurs, when you connect a new device and try debugging or running your applications one the device. For most devices, this works perfectly. For others, mostly new devices, Eclipse will show a lot of questionmarks instead of the device name.

The problem

The problem is (at least on Linux) that your user does not have access to the device. When you connect your phone or tablet to your computer, a special “file” is created in /dev. In order to debug your applications on the device, ADT will use this file for communicating with Android – uploading app, and so on. But if your system does not know this device, and is not configured to let your user access this device, it will only show up as “?????????????” and not let you use it for debugging.

The solution

There is more than one way to fix this. Below you will see two ways. The easy hack, and the right way. This works for Linux (Ubuntu, Debian and others like these). If you are running Windows, the problem is probably a missing USB driver. You can download the driver from here, where you will also find instructions on how to install it.

The wrong way (the easy hack)

A very easy quick-fix (read: hack) is to restart adb (the Android Device Bridge) as root. This is not the best way to do it, but if you’re in a hurry, it will work.

Navigate to your Android SDK directory, and in to the platform-tools dir. In here, you will find adb. To restart it as root, type the following.

  1. sudo ./adb kill-server
  2. sudo ./adb start-server

Now Eclipse and ADT should be able to see your device.

The right way

The right way to do it, is a little more complicated, as it is dependent on which device you have in your hand. But here we go…!

  1. Execute the command
    lsusb

     in a console. You will see some lines, describing the currently connected USB devices. Among those, there will be a line like

    Bus 001 Device 006: ID 0bb4:0ca9 High Tech Computer Corp.

     This is my HTC Flyer, and is has a “vendor ID” of 0bb4. Write down (or remember) this number.

  2. Navigate to /etc/udev/rules.d/
    cd /etc/udev/rules.d/
  3. In here you might find a file, called something like 99-android.rules (or with any other number in front). If so, go ahead and open it. If not, create a file and call it 99-android.rules
    nano 99-android.rules
  4. Now we need to add the vendor ID to the file. The line should look like this:
    SUBSYSTEM=="usb", SYSFS{idVendor}=="0bb4", MODE="0666"
  5. Save the file (ctrl+X, Y, <enter>). If you created a new file in step 3, please change the permissions as this:
    chmod a+g /etc/udev/rules.d/99-android.rules
  6. Reboot your computer. You should now be able to debug on your phone, without running the adb as root.
For convenience, here is a list of different devices, that you could copy/paste into your rules file:


#Acer
SUBSYSTEM=="usb", SYSFS{idVendor}=="0502", MODE="0666"
#Dell
SUBSYSTEM=="usb", SYSFS{idVendor}=="413c", MODE="0666"
#Foxconn
SUBSYSTEM=="usb", SYSFS{idVendor}=="0489", MODE="0666"
#Garmin-Asus
SUBSYSTEM=="usb", SYSFS{idVendor}=="091E", MODE="0666"
#Google
SUBSYSTEM=="usb", SYSFS{idVendor}=="18d1", MODE="0666"
#HTC
SUBSYSTEM=="usb", SYSFS{idVendor}=="0bb4", MODE="0666"
#Huawei
SUBSYSTEM=="usb", SYSFS{idVendor}=="12d1", MODE="0666"
#Kyocera
SUBSYSTEM=="usb", SYSFS{idVendor}=="0482", MODE="0666"
#LG
SUBSYSTEM=="usb", SYSFS{idVendor}=="1004", MODE="0666"
#Motorola
SUBSYSTEM=="usb", SYSFS{idVendor}=="22b8", MODE="0666"
#Nvidia
SUBSYSTEM=="usb", SYSFS{idVendor}=="0955", MODE="0666"
#Pantech
SUBSYSTEM=="usb", SYSFS{idVendor}=="10A9", MODE="0666"
#Samsung
SUBSYSTEM=="usb", SYSFS{idVendor}=="04e8", MODE="0666"
#Sharp
SUBSYSTEM=="usb", SYSFS{idVendor}=="04dd", MODE="0666"
#Sony Ericsson
SUBSYSTEM=="usb", SYSFS{idVendor}=="0fce", MODE="0666"
#ZTE
SUBSYSTEM=="usb", SYSFS{idVendor}=="19D2", MODE="0666"



Posted in Android by Kasper. No Comments

How to best organize your Android source

LibraryOne thing that can certainly speed up your development tasks when doing Android projects, is to reuse your Android source code. To do that, it is important to make sure that your Android source code is well organized and easy to find and reuse when you need it. Many of us are forgetting this, when things go fast, and we have to make deadlines. But if you take a little time to find some routines and methods that suits you, it can actually help you reach your deadlines in a lot more comfortable way. If you have ever found yourself writing code, feeling some kind of deja-vu, this post is for you.

Read the rest of How to best organize your Android source

Tags: , , , ,
Posted in Android by Kasper. No Comments

Android widget graphics

Hey!
I was looking for some graphics for creating Android apps and widgets, like the iPhone graphics from Geoff Teehan. And I found this. It has some very nice graphics for Photoshop, for designing widgets for Android. Check it out :)


Android: Widgets by ~bharathp666 on deviantART

Tags: , ,
Posted in Android by Kasper. 1 Comment

Android: Getting data from a webservice

A quick guide to get data from a web service, or HTTP service in general. This could be a RESTful web service, with POST, GET, PUT, DELETE and other methods.

Read the rest of Android: Getting data from a webservice

Posted in Android by Kasper. 2 Comments

Android: Converting InputStream to String

I know that this has been explained a lot of other places around the net, just to make it clear yet another time (and for my self to remember :) ). To convert an InputStream, which for instance could be a response from a HttpRequest, use the following method:

Read the rest of Android: Converting InputStream to String

Posted in Android by Kasper. 1 Comment

New countries in Android Market! Finally!!

Android MarketFor the first time since Android Market opened up, in October 2008, Google has added new countries in which you can buy and sell applications.

The following countries are open for selling applications as per September 30, 2010:

Argentina, Australia, Belgium, Brazil, Canada, Denmark, Finland, Hong Kong, Ireland, Israel, Mexico, New Zealand, Norway, Portugal, Russia, Singapore, South Korea, Sweden, Switzerland and Taiwan.

For buying applications, the following countries will open over the next two weeks:

Argentina, Belgium, Brazil, Czech Republic, Denmark, Finland, Hong Kong, India, Ireland, Israel, Mexico, Norway, Poland, Portugal, Russia, Singapore, Sweden, and Taiwan.

Great news, Google! :)

Read more at the Android Developer’s Blog

Posted in Android by Kasper. No Comments

The game layer

Seth Priebatsch has made this Ted talk, about how “the next thing” will be the game layer, on top of the world. Especially on top of the social networks, which in it selfs was the big thing in last decade. Not that social networks is old fashion, but as the world evolves, new things has to come in to the picture, and we need to figure out new ways to use it.

Watch it, it’s a great point of view for thinking mobile applications for the next decade ;)

Android vs iPhone development

iPhone development is closed, you can’t do the things you want to, everything has to be the way Mr. Jobs wants it. Android on the other hand is fragmented, old-school-java, and Google lets you create applications that empties peoples bank accounts.

This is some of the comments I have heard and read, around the internet. To some extends, some of the arguments might be somehow correct, depending on your own view on it.

Read the rest of Android vs iPhone development

Posted in General by Kasper. No Comments