Posts

Showing posts from February, 2015

Android - Activity started in same task despite FLAG_ACTIVITY_NEW_TASK

Image
    Android's documentation on FLAG_ACTIVITY_NEW_TASK is not clear in terms of the impact caused by taskAffinity. It just indicates that the desired activity would be started in a new task and user would be able to see multiple tasks from the recent tasks list. However, this isn't always the case.         Intent intent = new Intent();         intent.setClass( this, TestActivity.class );         intent.setFlags( Intent.FLAG_ACTIVITY_NEW_TASK );         startActivity( intent );    The TestActivity is launched into the same task as that of the launching activity when both activities share the same task affinity. By default, all activities in an application share the same task affinity unless any of them have a different affinity set explicitly on them. In the latter case, TestActivity is indeed launched into its own task and users can see multiple tasks for the same applic...

Android - Google Navigation and Music Player Audio interaction

   Google Navigation's audible instructions works well with music playing applications like Play Music,  Amazon prime music. Music apps basically reduce their stream volume during the navigation instructions and eventually reverts back to the original volume. This implementation is based on AudioManager APIs.    Navigation app requests for a transient audio focus which is relayed by the framework to the music application holding audio focus.        AudioManager am = mContext.getSystemService(Context.AUDIO_SERVICE);        am.requestAudioFocus(afChangeListener,                              AudioManager.STREAM_MUSIC,                               AudioManager.AUDIOFOCUS_GAIN_TRANSIENT_MAY_DUCK );  This event is notified to music app via its OnAudioFocusChan...

Android - Removing anonymous Runnables from Handler

     Android's Handler has convenient APIs to remove messages after they are posted to a looper thread. Messages are identified by an integer and this makes it easy to remove them via removeMessages(int)  However, this doesn't work with Runnables which aren't associated with a message type. Besides, applications might want to remove multiple Runnables of a specific type.     Handler has an API  removeCallbacks(Runnable r ) to remove the runnable but this requires that application book keep the runnable and needs more work when multiple instances are posted to the handler. Besides, applications tend to post anonymous Runnables.    Fortunately, Handler has another API to remove all messages and runnable  removeCallbacksAndMessages(Object token)  corresponding to the specified token. The same token can be associated with multiple runnables and serves the purpose with ease.    However, there isn't a straightforward API...

Cyanogenmod - Privacy Guard's location access false positive

Image
     Cyanogenmod privacy guard feature is so promising and lets users get better idea about application's permissions. This is something similar to the feature available in iOS and user get to decide if they want to allow/deny access at runtime. Ofcourse, this doesn't guarantee that the application would be functional at all times but its better to be safe than sorry. This is even more helpful for application developers using 3rd party libraries.     However, i recently came across a warning in an application about location access without any such permission declaration in its manifest. This was seen in OnePlus One running CM 11. This is kind of creepy, especially when features like Privacy Guard isn't enabled by default and is available only in CM builds. Things like this could get application developers in legal trouble. Having said this, its still possible that a framework bug could lead to false positives and mislead users.     Privacy guar...

Android - Monkey not to expand status bar

Image
   Android's monkey supports package specific testing and application developers look to use this to automate some tests. However, monkey doesn't guarantee that events would be sent only to the application window corresponding to the package. Events could be sent to both status bar and navigation bar. This could cause issues in some applications as settings via status bar could be updated and the application could be sent to background via navigation bar's home key.    The obvious work around is to look for alternatives to avoid/ignore both status bar and navigation bar. However, this wouldn't really work as navigation within the app via back key can't be tested.   Fortunately, Lollipop's screen pinning feature could be used to ensure that events are sent only to the application. This can be enabled via Settings > Security > Screen pinning. Next, the desired app can be pinned via recent app list.    Android framework takes care that t...

Android - activated state vs selected state

  Android's documentation isn't clear in terms of using activated and selected state drawable resources for a view. Both activated and selected state is passed down to child views,     public void setActivated(boolean activated) {             ...             dispatchSetActivated(activated);         }     }     /**      * Dispatch setActivated to all of this View's children.      */     protected void dispatchSetActivated(boolean activated) {     }     public void setSelected(boolean selected) {             ...             dispatchSetSelected(selected);         }     }     /**      * Dispatch setSelected to all of this View's children.      */     protect...

Android - Hiding methods from Javadoc

      Android platform's javadoc uses a custom doclet (com.google.doclava.Doclava) to support a custom tag @hide. This ensures that the methods, classes marked as hidden isn't included in the generated javadoc and this is how android ensures internal and non-public APIs aren't documented.       3rd party library developers often have a similar need to generate their library's documentation. Fortunately, yWorks comes to rescue. yWorks is a javadoc extension known early as yDoc. This offers a custom doclet to hide methods, classes from the generated docs. Prerequisites    1) Download and unzip the community edition at  http://www.yworks.com/en/products_download.php?file=yworks-uml-doclet-3.0_02-jdk1.5.zip    2) Refer to man pages for yWorks at  http://www.yworks.com/products/yDoc/doc/usersguide.html#install    3) Specify tag @y.exclude for non-public methods and classes /**      ...