[Android] Sugar ORM is not creating tables on DB creation/migration

I was having this issue in two scenarios:

– Database creation from zero (app just installed)
– Database migration (for example from v2 to v3)

there were two tables that weren’t being created.

I discovered that they both had only one constructor, with parameters.
After adding an empty constructor, both tables were created.

public NotificationDBEntry() {

public ProjectDBEntry() {

So there are two choices to make it work:
– In classes with no constructor, it will work because the default one is the empty constructor
– In classes with a non-empty constructor, it is mandatory to add an empty constructor.

Hope this saves you time!

[Android] Configuring a quick test environment

In order to start writing tests for our app, one quick solution could be this one:

1.- Adding junit to our build.gradle file

testCompile 'junit:junit:4.12'

2.- Creating the test folder structure
This can be done with Android Studio, or directly in your file explorer (finder, nautilus, etc). Create the folder


where the app’s package name would be com.companyname.appname (substitute by yours).

3.- Creating a sample test
Inside the recently created folder, create a file named ProjectTest.java and copy this content:

public class ProjectTest {
public void shouldCompare1To1() throws Exception {
assertEquals(1, 1);

4.- Running the tests in console
Go to terminal, move to your app’s folder and do

./gradlew test

If everything went fine, you should have a single test passing

[Android] imeOptions not working on EditText (actionNext, actionDone)

Don’t forget to add

<item name=”android:inputType”>text</item>


<item name=”android:inputType”>textPassword</item>

to your EditText’s style

Directly on XML:


[Marmalade SDK] Warning: Using default deployment icon(s)

I just found this error when deploying my Marmalade App to Android.

As it’s explained on this thread, we need to supply a default generic icon, apart from the android-specific icon options (like android-icon-xhdpi).

For those using the hub, there is a solution in the previously mentioned thread. For those who, like me, still use .mkb files, this is how I’ve solved it.


... rest of the mkb

Deploy tool is not complaining about this anymore ūüôā

[Android SDK] Useful keyboard shortcuts for Android Studio

The ones I use most:

While developing

Alt+enter over class in code (.java): Quick assistance (import class, override methods, etc)
Alt+enter over string in code (.java): Extract string resource (include in res/values/strings.xml)
Alt+enter over string in resource file (.xml): Extract string resource (same as previous)

Shift+Cmd+F9: Make module (only current module)
Shift+Cmd+UP: Move this line UP (in .java)
Shift+Cmd+DOWN: Move this line DOWN (in .java)

Ctrl+R (aka ^ R): Run
Ctrl+Alt+D: Debug
Ctrl+Alt+I: Auto-indent code

Cmd+Backspace: Remove current line (VERY USEFUL)
Cmd+D: Duplicate current line (VERY USEFUL)

Cmd+F9: Make project  (all modules, app, wear, glass..)

When debugging:

F8: Step over
Cmd+Alt+R: Continue execution (what a weird shortcut this one)

I’ll keep completing it everytime I find a really useful one. Feel free to post your own in comments!

[Android SDK] Installing Gradle in command-line shell (MacOS X)

Once we install Android Studio (or just gradle itself), it is very comfortable to have it added to our PATH, which makes us able to run commands like

gradle task1

from any Android project’s folder.

One way to do that is adding gradle’s path to our PATH variable. Under¬†MacOS X, this is done with the following steps.

1.- In terminal:

export GRADLE_HOME=/Applications/Android\ Studio.app/Contents/gradle/gradle-2.2.1

*We assume we’re using the bundled Gradle that comes with Android Studio. You can place gradle anywhere else, like¬†your /Users/user folder, and use this location. Example:

export GRADLE_HOME=/Users/jimmy/gradle-2.2.1

2.- Now, let’s have a look at our PATH variable. In terminal:

echo $PATH

It should look like:

/usr/bin:/bin:/usr/sbin: ... (more system folders separated by ":" )

To¬†append gradle’s folder at the end of¬†our path:


Now, execute “echo $PATH” again, and you should see gradle’s folder appended in the end, separated by a “:”.

If you were successful on step 2, you should now be able to execute:

gradle –version

And see an output like:

Gradle 2.2.1
Build time:   ...
Build number: none
Revision:     6fcb59c06f43a4e6b1bcb401f7686a8601a1fb4a
Groovy:       2.3.6
Ant:          Apache Ant(TM) version 1.9.3 compiled on December 23 2013
JVM:          1.6.0_65 (Apple Inc. 20.65-b04-462)
OS:           Mac OS X 10.9 x86_64

Hope it helps!

[Android SDK] java.lang.IllegalArgumentException: Service Intent must be explicit – on Android 5.0 Lollipop

[Refloated post from 2014, treasure from the past]

I just noticed that one of my Apps is getting continous crash reports on Google Play. The crashes are related to IAPs (In-App Purchases, Billing library), exactly on this line:

Intent serviceIntent = new Intent(“com.android.vending.billing.InAppBillingService.BIND”);
mContext.bindService(explicitIntent, mServiceConnection, Context.BIND_AUTO_CREATE);

According to this SO question, there are two possible solutions:

1.- Turning the implicit intent (the serviceIntent var above) into an explicit intent

1.1.- Copy this code for createExplicitFromImplicitIntent() method found in android-develop blog:

* Android L (lollipop, API 21) introduced a new problem when trying to invoke implicit intent,
* "java.lang.IllegalArgumentException: Service Intent must be explicit"
* If you are using an implicit intent, and know only 1 target would answer this intent,
* This method will help you turn the implicit intent into the explicit form.
* Inspired from SO answer: http://stackoverflow.com/a/26318757/1446466
* @param context
* @param implicitIntent - The original implicit intent
* @return Explicit Intent created from the implicit original intent
public static Intent createExplicitFromImplicitIntent(Context context, Intent implicitIntent) {
// Retrieve all services that can match the given intent
PackageManager pm = context.getPackageManager();
List resolveInfo = pm.queryIntentServices(implicitIntent, 0);

// Make sure only one match was found
if (resolveInfo == null || resolveInfo.size() != 1) {
return null;

// Get component info and create ComponentName
ResolveInfo serviceInfo = resolveInfo.get(0);
String packageName = serviceInfo.serviceInfo.packageName;
String className = serviceInfo.serviceInfo.name;
ComponentName component = new ComponentName(packageName, className);

// Create a new intent. Use the old one for extras and such reuse
Intent explicitIntent = new Intent(implicitIntent);

// Set the component to be explicit

return explicitIntent;

1.2.- Add this line to your IabHelper implementation:

Intent serviceIntent = new Intent("com.android.vending.billing.InAppBillingService.BIND");
Intent explicitIntent = createExplicitFromImplicitIntent(mContext, serviceIntent);
mContext.bindService(explicitIntent, mServiceConnection, Context.BIND_AUTO_CREATE);

2.- Setting the intent’s package name

Add this line


Choose the one of your preference, then re-submit your app to Google Play. This should fix the crash reports!

Thanks to the authors of both solutions. Have a nice coding day!

[Android] OrmLite performance test: Insert vs Bulk-insert

1.- Parse a 800 Kb JSON file into an array
2.- Insert all the parsed entities into a table (Using OrmLite)
3.- Empty the table
4.- Perform the same insertion, but using Bulk-insert (one single transaction for all inserts, instead of a transaction for each)

Tested code:

protected void onCreate(Bundle savedInstanceState) {
strb = new StringBuilder();
mTxt1 = (TextView) findViewById(R.id.txt1);

long startMs = System.currentTimeMillis();
ArrayList points = parsePointsJson_v1(this);
long endMs = System.currentTimeMillis();

strb.append(points != null ? points.size() : "")
.append(points != null ? " points parsed" : " parse error")
.append(" - ").append(endMs-startMs).append(" milliseconds\n");

int insertCount=0;
final Dao poiDao = getHelper().getPointOfInterestDao();

startMs = System.currentTimeMillis();
for(PointOfInterest p : points){
endMs = System.currentTimeMillis();
.append(" normal insertions - ")
.append(endMs-startMs).append(" milliseconds\n\n");

startMs = System.currentTimeMillis();
endMs = System.currentTimeMillis();
strb.append("Empty Points table took: ").append(endMs-startMs).append(" milliseconds\n");

final ArrayList finalPoints = points;
TransactionManager.callInTransaction(poiDao.getConnectionSource(), new Callable(){
public Void call() throws Exception {
long start = System.currentTimeMillis();
int insertCount2 = 0;
for(PointOfInterest fp : finalPoints ){
long end = System.currentTimeMillis();
strb.append(" Bulk insert: ").append(insertCount2).append(" insertions. Took: ").append(end-start).append(" milliseconds\n");
return null;

}catch(SQLException e){
strb.append(" an exception ocurred while inserting: ").append( e.getMessage()).append(" ").append(insertCount).append(" insertions were made");
}catch(Exception e){
strb.append(" Exception bulk-inserting: "+ e.getMessage());


Results on some real devices:

HTC Sensation z710e

Samsung Galaxy SII
BQ Aquaris 5

A little compilation of the results: