How Alipay’s Lock‑Screen Component Delivers Real‑Time Data on Android
This article explains the technical background, implementation details, lifecycle management, multi‑business registration, power‑consumption analysis, and real‑world use cases of Alipay's lock‑screen component that shows app data on the Android lock screen.
1. Technical Background
Mobile devices aim to quickly surface app information to users through external entry points such as the negative screen, widgets, notification bar, and Huawei’s real‑time capsules.
Lock‑screen components keep app data visible after the screen is turned off, allowing users to view information without unlocking the app again.
2. On‑Device Effect
Using Alipay Sports (test case) and Travel services (test case), the lock‑screen component can display real‑time sport data (time, distance, pace) and travel QR codes directly on the lock screen.
3. Technical Details
3.1 Lock‑Screen Listening
Two ways to listen for lock‑screen events: direct code checks (active) or broadcast reception (passive). Receiving lock‑screen broadcasts is the preferred method.
private ScreenBroadcastReceiver mScreenReceiver;
private class ScreenBroadcastReceiver extends BroadcastReceiver {
private String action = null;
@Override
public void onReceive(Context context, Intent intent) {
action = intent.getAction();
if (Intent.ACTION_SCREEN_ON.equals(action)) {
// screen on
} else if (Intent.ACTION_SCREEN_OFF.equals(action)) {
// screen off
} else if (Intent.ACTION_USER_PRESENT.equals(action)) {
// unlocked
}
}
}
private void startScreenBroadcastReceiver() {
IntentFilter filter = new IntentFilter();
filter.addAction(Intent.ACTION_SCREEN_ON);
filter.addAction(Intent.ACTION_SCREEN_OFF);
filter.addAction(Intent.ACTION_USER_PRESENT);
context.registerReceiver(mScreenReceiver, filter);
}3.2 Lock‑Screen Floating Window
The floating window can be created via WindowManager or an Activity. The WindowManager approach requires predefined UI parameters and is less suitable for rapid third‑party integration.
WindowManager = (WindowManager) mContext.getSystemService(Context.WINDOW_SERVICE);
mWmParams = new WindowManager.LayoutParams();
// set transparent background
mWmParams.format = PixelFormat.RGBA_8888;
// make window non‑focusable
mWmParams.flags = WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE;
// position at left top
mWmParams.gravity = Gravity.LEFT | Gravity.TOP;
mScreenHeight = mWindowManager.getDefaultDisplay().getHeight();
mWmParams.x = 0;
mWmParams.y = mScreenHeight / 2;Using an Activity, flags are added in onCreate to allow the window to appear over the lock screen.
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
final Window win = getWindow();
win.addFlags(WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED
| WindowManager.LayoutParams.FLAG_DISMISS_KEYGUARD
| WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON
| WindowManager.LayoutParams.FLAG_TURN_SCREEN_ON);
// custom code
}3.3 Optimization Items
Repeated lock‑screen wake‑up: add wake‑lock code in onNewIntent or other lifecycle methods.
Slide‑to‑unlock: delegate touch events to GestureDetector for gesture handling.
4. Rapid Integration
Third‑party businesses register and unregister the lock‑screen component through a unified manager.
// Register custom handler
public void registerCustomHandler(final LockScreenCustomInterface customInterface) {
uiHandler.post(new Runnable() {
@Override
public void run() {
try {
unregisterCustomHandlerOnUI(customInterface.getBizId());
customList.add(customInterface);
registerScreenBroadcast();
} catch (Exception e) {
LoggerFactory.getTraceLogger().error(TAG, e);
}
}
});
}
// Unregister custom handler
public void unregisterCustomHandler(final LockScreenCustomInterface customInterface) {
uiHandler.post(new Runnable() {
@Override
public void run() {
unregisterCustomHandlerOnUI(customInterface.getBizId());
if (customList == null || customList.isEmpty()) {
unregisterScreenBroadcast();
}
}
});
}4.2 UI and Data
Custom UI can be provided by the business or use the component’s generic UI. Data is managed by BgServiceDataManager, which binds data to the business ID during the component’s lifecycle.
5. Lifecycle Awareness
The component defines several lifecycle callbacks (onCreate, onShow, onHide, onUpdateData, onSubscribed, onUnSubscribed, onObserve, onDestroy) that allow third‑party logic to react appropriately.
6. Multi‑Business Registration Management
Multiple businesses can register simultaneously. The component uses a priority system: high‑priority services display first; equal priority services are ordered by registration time (newer first).
7. Power Consumption Analysis
Using Battery Historian, a demo kept the screen bright for 30 minutes; the lock‑screen component consumed only 0.01 % of battery power and did not cause noticeable heating or lag.
8. Industry Cases
8.1 Airline Check‑In
The airline app displays the boarding pass on the lock screen, allowing users to view it without unlocking the phone.
8.2 Keep Fitness App
During a run, the Keep app keeps sport data visible on the lock screen even when the device goes to sleep, and a swipe unlock returns to the main screen.
Alipay Experience Technology
Exploring ultimate user experience and best engineering practices
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.
