Jump to content

  • Log In with Google      Sign In   
  • Create Account

We're offering banner ads on our site from just $5!

1. Details HERE. 2. GDNet+ Subscriptions HERE. 3. Ad upload HERE.


Android API Quriks


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
2 replies to this topic

#1 NinJava   Members   -  Reputation: 108

Like
2Likes
Like

Posted 18 August 2012 - 01:01 PM

Hi,

I'd like to discuss some issues I encountered when working with Android during development of our game engine.
I'll iteratively add quirks to this topic on the go, please leave your opinions and don't hesitate to add any noteworthy quirks you encountered.
  • Application.onCreate()

    What would you do when you want some code to be executed prior to the instansiation of a service/activity/content provider/broadcast recevier in your app?

    Simple, create a class, extend it from Application and override onCreate().
    Now you think you're guaranteed that it'll be invoked first before everything, you happily initialize any long term data to find out
    that data is not available to you... w00t?!

    Android API docs state this:

    public void onCreate ()
    Since: API Level 1
    Called when the application is starting, before any other application objects have been created. [...]
    After some debugging I realized that the class trying to access that particular piece of data is actually initialized from a ContentProvider, and so it seems that ContentProvider's are in fact, initialized BEFORE Application.onCreate()

    Workaround

    Taken from: http://stackoverflow...ider-initialize


    		public class ApplicationController extends Application {
    			@Override
    			protected void attachBaseContext(Context base) {
    				super.attachBaseContext(base);
    	    	   // Initialize data here
    			}
    		}
    
  • Math.abs(long)

    Ever used Math.abs()? sure you did, using library functions is encouraged even if their implementation seems trivial.
    But what if they don't work? Or worse, don't work *sometimes* w00t???

    A couple of days ago we started debugging those performance issues we had with a certain game on the Samsung Galaxy Ace device, and from time to time we got an exception in a method which did an approx. of arcsin() math function.

    The method passed many unit tests which tested various edge cases but alas we kept getting an ArrayIndexOutOfBounds exception even tho the index accessed in the array which was used in the method was suppost to be valid given the input.

    After some debugging with log sessions, annoying given the randomness of the bug, we realized that Math.abs() did in fact returned the absolute value of the result but also turned the 32nd bit in it for no apparent reason.

    At first we suspected that our phone has memory corruption, but in a day after a colleague approached me and told me that
    There's in fact a bug with JIT on some ARM devices, and Math.abs being an invocation to an interinsic function got inlined during JIT and something there made it go haywire.

    There's a bug on google at that: http://code.google.c...detail?id=27007

    Workaround

    Turn off dalvik JIT

    Real World Workaround

    Implement Math.abs yourself :-)
More quirks will come... Posted Image

Cheers
Max Raskin, Platform Developer @ Mominis

Sponsor:

#2 NinJava   Members   -  Reputation: 108

Like
0Likes
Like

Posted 02 September 2012 - 07:15 AM

3. Consider this - content providers which have the same fully qualified class but have different authoreties

Package 1 manifest:

<provider
android:name="foo.bar.MyContentProvider1"
android:authorities="myfoo.bar.mycontentprovider1"
android:enabled="true"
android:exported="true" />

Package 2 manifest:

<provider
android:name="foo.bar.MyContentProvider1"
android:authorities="myfoo.bar.mycontentprovider2"
android:enabled="true"
android:exported="true" />

When I call

getContentResolver().update(
Uri.parse("content://myfoo.bar.mycontentprovider1"),
values, null, null);

getContentResolver().update(
Uri.parse("content://myfoo.bar.mycontentprovider2"),
values, null, null)

And where:

Package 1 content provider having:

@Override
public int update(Uri uri, ContentValues values, String selection,
String[] selectionArgs) {
Log.d("w00t", "hey im from package1!");
return 0;
}

Package 2 content provider having:

@Override
public int update(Uri uri, ContentValues values, String selection,
String[] selectionArgs)
Log.d("w00t", "hey im from package2!");
return 0;
}

What do you expect be shown in logcat?

If you thought, like I did

hey im from package1!
hey im from package2!

WRONG!

what will be actually shown is:

hey im from package1!

Possibly, the first provider with fully qulaified name of foo.bar.MyContentProvider1 found is the first one queried.

Workaround

Either: Put the content provider under your package name e.g org.mycomapny.app.foo.bar.MyContentProvider1
Or suffix your content provider class name e.g foo.bar.MyContentProvider1_myAppX
Max Raskin, Platform Developer @ Mominis

#3 Serapth   Crossbones+   -  Reputation: 5691

Like
0Likes
Like

Posted 04 September 2012 - 04:05 PM

... try using ADB over a USB3 port.

Or frankly, any of the imaging or sound api's circa 2.2.

God I hate(d) Android development.




Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS