Android – pass touch events to a child view

AOSP offers a delegate mechanism to modify the touchable area of Views, but this may not always behave as expected. A common use-case is having a View shown within a constrained area, but wanted to react to scrolling gestures from anywhere on the screen – e.g., imagine a RecyclerView on a landscape tablet that design […]

Android – (visually) clone a View

While there’s nothing in the Android framework can create a duplicate of an existing View, it’s trivial do duplicate one visually. Just call someView.draw(canvas) in the onDraw of the View you want to serve as the duplicate. E.g.,

Copy files from Android device or emulator to computer

from here Copy it from internal to SD card, then ADB pull from SD card to host machine.

Android – confirm preference change

If you’re using the Preferences API in Android, and want to confirm (show a dialog, perform a test, etc) before a Preference is updated, you need to find that Preference item and call setOnPreferenceChangeListener to a custom listener. This can work in conjunction with PreferenceManager.registerOnSharedPreferenceChangeListener, you just need to return false to have the Preference […]

Android – isTaskRoot returning false incorrectly

Some Launchers will launch an app at it’s LAUNCH activity on top of the last point the user was at. Imagine: 1. User opens app. 2. The Launcher Activity is designated at Activity A, so that’s what opens. 3. User navigates several Activities deep and ends up at Activity D (A > B > C […]

Android – Restart App

The title isn’t exactly accurate – you can’t “restart” an app per se – but you can get pretty close:

This starts the Activity specified in your manifest as the “LAUNCHER”, in a new task stack (history), and clear the existing stack.

Android – get system defined ActionBar size (height)

In xml, you can use ?attr/actionBarSize, but if you need access to that value in Java…

Android – View traversal / walker / finder utilities

Android – LinearLayout with dividers (separators)

Add (or amend) your values/attrs.xml to include:

Some layout:

And the class:

Android – launch modes and multiple intents

The behavior here isn’t quite what I expected, or gather from the documentation. If you have <activity android:name=”.SomeActivity” android:launchMode=”singleTop” /> Then you start SomeActivity multiple times:

You’ll get only one instance of SomeActivity at the top of the stack (as the singleTop launch mode promises), but you’ll notice that if you finish() or hit […]