Wednesday, April 6, 2011

Performing research on the Android Market

There are various out there that can help perform a research on Android applications.
  1. Android Market application
  2. Android Market web site - Has difference number of downloads scale. While the highest value in the Market application is >250K, in the web site there are different values: 50K-100K, 100K-500K, 500K-1M, 1M-5M, 5M-10M, 10M-50M
  3. AndroLib - Has application rating (stars) history
  4. AndroidZoom - Has application history: release dates & events (when the application passed a download group (e.g. 10K-50K, 50K-250K).
  5. AppAnnie - Market analytics (alternatives: Android App Tracker - Has application market ranking history, AndroidRanking.com - Another Android market tracking site).
If you have more interesting sites, please share.

Update Jan-2013: VisionMobile just lunched a great site for developers called Developer Economics that contain a tools atlas with all the tools that can help the developer.

Saturday, April 2, 2011

onActivityResult not called in time

I wrote a small program that needed to use a preference screen. After the preferences were updated the application needs to update. To do that I used startActivityForResult to start the preferences screen, and onActivityResult to update the application.

Problem: onActivityResult wasn't called in time. Using Toast I've noticed it was called BEFORE the preferences screen opens.

Solution: In my case - the application was defined as launchMode=singleInstance, removing this put things back to place.

Note: This is true for Android 2.3.3. I didn't check the documentation to see if it's a normal behavior or an issue.

Sunday, February 13, 2011

Problem uninstalling Android SDK samples

This is the second time it happens to me so I've decided to write a post about it.

Problem: in the "Android SDK and AVD Manager"/"SDK Setup" selecting "Samples for SDK ..." package and clicking 'delete' deletes the content of the samples folder, but does not remove the entry from the "Android SDK and AVD Manager".

Solution:
1. Close the "Android SDK and AVD Manager"/"SDK Setup" (close the eclipse if it's running).
2. Delete the SDK specific samples folder. If the folder is locked kill any 'java.exe' process running (or reboot).
3. Restart the "Android SDK and AVD Manager"/"SDK Setup"

Distance on earth calculation in SQL

Here's how to create an SQL function to calculate the distance (in KM) between to points on earth. This is an estimation since the distance is calculated as if the earth was round, but it's close enough for most purposes:

Friday, January 21, 2011

TimePicker & DatePicker with keyboard edit problem

Problem: When using the TimePicker & DatePicker objects in an AlertDialog (and probably anywhere else), the time & date seem to not to update when the user is editing the value using a keyboard (or soft keyboard).

Solution: Before calling the functions to get the date & time from the objects call TimePicker or DatePicker clearFocus() method.

I found few threads talking about this problem without a solution. I found the solution when I looked at the TimePickerDialog source code which did not suffer from this problem.

Android SQLite Alter Table

When upgrading SQLite database sometimes you need to change the tables scheme. The problem is that SQLite Alter Table SQL format does not support all the options you might need (specifically - dropping columns, changing column types, renaming columns).

One way around this issue is to create a new table & copy the data to the new table. There are few options here, but the best way (I think) is as follows:
1. Create new table in the new format.
2. Copy the data.
3. Drop the original table
4. Rename the new table

For example:
BEGIN TRANSACTION;
CREATE TABLE t_new(a,b);
INSERT INTO t_new SELECT a,b FROM t;
DROP TABLE t;
ALTER TABLE t_new RENAME TO t;
COMMIT;


IMPORTANT: As far as I know 'execSQL' of 'SQLiteDatabase' will NOT run multiple commands. You should run each SQL command in a separate 'execSQL' call (the transaction can be handled from the SQLiteDatabase, not need for explicit SQL commands).

Thursday, January 20, 2011

Build.VERSION.SDK_INT on Android 1.5

It won't be long before all Android 1.5 devices will disappear, until then it's a good idea to support them. The problem is the 'Build.VERSION.SDK_INT' was introduced only on Android 1.6, and before that there were only string values.

Here's a work-around this issue - it will return the correct value for Android 1.5+:


Note: the internal class is required since the Java virtual machine checks if a class is valid before loading it. In our case, a java VM running Android 1.5 will not be able to load Build.VERSION.SDK_INT and will crash.

UPDATE: Added VerifyError catch to prevent exceptions on some weird Android 1.5 devices.