Mobile Development 9 min read

Design and Refactoring of a Mobile Schema Dispatch Mechanism

This article explains the concept of custom schema URLs in mobile development, describes the problems of a growing ad‑hoc implementation, and presents a refactored, configuration‑driven architecture that provides automatic matching, self‑documenting schemas, and integrated testing for Android apps.

Qunar Tech Salon
Qunar Tech Salon
Qunar Tech Salon
Design and Refactoring of a Mobile Schema Dispatch Mechanism

In mobile development, a [scheme:][//authority][path][?query][#fragment] schema is a custom resource identifier similar to a URL with a custom protocol, used for low‑coupling interoperability between heterogeneous systems.

Schemas enable actions such as opening a specific app from a touch page, triggering functions across apps, or facilitating component interaction in a modular architecture like Qunar.

The existing implementation relied on scattered if statements for each schema, leading to maintenance difficulties as the number of schemas grew to dozens.

The proposed solution introduces a simplified model where a schema is matched to an execution point via a configuration‑based dispatch mechanism.

The key idea is to use a configuration (e.g., Java interface with annotations) that defines the schema expression, the handler class, documentation, and sample data.

public interface SchemaHandler {
    void handle(SchemaContext context, Uri originalSchema, Map
params, Bundle extra);
}

A Registration component loads these configurations, builds SchemaPattern objects, and registers them for matching.

public
void setup(Class<Protocol> contract) {
    Method[] methods = contract.getMethods();
    for (Method method : methods) {
        Schema schemaConfig = method.getAnnotation(Schema.class);
        Class
executor = schemaConfig.executor();
        Producer producer = new Producer(method, executor);
        SchemaPattern pattern = new SchemaPattern(schemaConfig, producer);
        SchemaDocument schemaDoc = method.getAnnotation(SchemaDocument.class);
        pattern.setDocument(schemaDoc);
        patterns.add(pattern);
    }
}

Annotations also generate self‑explanatory documentation, allowing the app to dump supported schemas with their parameters and descriptions.

@Retention(RetentionPolicy.RUNTIME)
@Target({ElementType.METHOD})
@Inherited
public @interface SchemaDocument {
    String title();
    String content() default "No description";
    String sample() default "";
}

The system integrates with automated testing by providing schema sample sets, verifying supported/unsupported schemas, and comparing UI results across releases.

Compared with open‑source solutions like Airbnb's DeepLinkDispatch and Alibaba's ARouter, this approach avoids a full rewrite by only modifying the matching and dispatch layer, preserving existing business logic while reducing refactor risk.

The refactored dispatcher has been extracted into a shared library (Qunar Schema Dispatcher) for reuse across other business lines.

MobileAndroidtestingconfigurationdocumentationschemadeep linking
Qunar Tech Salon
Written by

Qunar Tech Salon

Qunar Tech Salon is a learning and exchange platform for Qunar engineers and industry peers. We share cutting-edge technology trends and topics, providing a free platform for mid-to-senior technical professionals to exchange and learn.

0 followers
Reader feedback

How this landed with the community

login Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.