DEV Community

lyc233333
lyc233333

Posted on

Exploration of Hongmeng Next development model: From "building building blocks" to "cross-end collaboration" 🧱

Hi~ I am Xiao L!The development model of Hongmeng Next is like "fitting Lego" - splitting the application into independent modules, and then "assembly" it into a cross-device experience with distributed capabilities.Today, we will show you three key innovation points to unlock new development ideas~

1. Modular development: Let the application "plug and play" πŸ”Œ

Core idea

  • Atomic Split: Split the application into independent modules (such as login modules, payment modules)
  • Loading on demand: The main module only contains necessary functions, and the secondary module is dynamically downloaded
  • Cross-project reuse: A module can be called by multiple applications

Practical Example: Modularization of E-commerce Applications

β”œβ”€β”€ main_module # main module (home page, search)
β”‚   └── src  
β”œβ”€β”€ user_module # User Center module (can be independently tested)
β”‚   β”œβ”€β”€ src  
└── config.json (declare dependency: network_module)
└── network_module # network request module (general capability)
    └── src  
Enter fullscreen mode Exit fullscreen mode

** Advantages**:

  • Teams can develop different modules in parallel (such as group A is used as interface, group B is used as network logic)
  • Module hot update: Users can get new features without reinstalling the application

2. ArkUI declarative development: "What you see is code" πŸ“

Core features

  • State Driver Interface: Use @State/@Link to mark data, and automatically update the view when changes
  • Responsive layout: A set of codes is adapted to mobile phone/flat tablet/car screen
  • Componential packaging: Custom components can be reused (such as general buttons, input boxes)

Code comparison: Login interface development

Traditional imperative (Android)

Button btn = new Button(this);  
btn.setText("Login");
btn.setOnClickListener(new View.OnClickListener() {  
    @Override  
    public void onClick(View v) {  
// Logical processing
    }  
});  
Enter fullscreen mode Exit fullscreen mode

Hongmeng Declarative (ArkUI)

@Entry  
@Component  
struct Login {  
  @State isLoading: boolean = false;  

  build() {  
Button(isLoading? 'Loading...' : 'Login')
      .onClick(() => this.isLoading = true)  
.loading(isLoading) // Automatically switch loading status
      .width('80%')  
  }  
}  
Enter fullscreen mode Exit fullscreen mode

Efficiency improvement:

  • 50% reduction in code volume+
  • Separate interface logic from business logic, more intuitive debugging

3. Distributed development: Let the equipment "team collaboration" πŸ‘₯

Core abilities

  1. Cross-device task scheduling
  2. Mobile phone initiates tasks, automatic relay of flat panel/car machine
   import taskManager from '@ohos.distributedTask';  
taskManager.transferTask(deviceId, 'editDocument'); // Migrate editing tasks to the tablet
Enter fullscreen mode Exit fullscreen mode
  1. Equipment capability sharing
  2. Calling sensors/camerases for other devices
   import deviceAbility from '@ohos.deviceAbility';  
const camera = deviceAbility.acquire('remote:camera:deviceId'); // Use remote camera
Enter fullscreen mode Exit fullscreen mode
  1. Distributed Data Storage
  2. Real-time synchronization of multi-device data
   import distributedData from '@ohos.distributedData';  
distributedData.subscribe('todoList', (data) => { /* Data change callback */ });
Enter fullscreen mode Exit fullscreen mode

Scenario case: Cross-device meeting record

  • Mobile phone: Start the meeting record application and call the local microphone to record
  • Tablet: Automatically join collaboration, display text translation in real time (using tablet computing power)
  • Smart Wear: After the meeting, the watch vibration reminder will be kept.

Code Key Snippet:

// The main device (mobile phone) initiates collaboration
distributedTask.startCollaboration([deviceId]);  

// Receive tasks from the device (tablet)
onTaskReceived(task => {  
  if (task.type === 'recordMeeting') {  
startTranscribing(); // Start text translation
  }  
});  
Enter fullscreen mode Exit fullscreen mode

4. Development efficiency tools: "One-stop" to complete the entire processπŸš€

1. New features of DevEco Studio 4.0

  • Real-time preview: After modifying the code, the multi-device emulator refreshes the interface synchronously
  • Module dependency analysis: Visually view module call relationships and quickly locate conflicts
  • Automated Test: Generate cross-device test cases with one click

2. Low-code development platform

  • Applicable scenarios: Quickly build tool applications (such as attendance check-in, approval process)
  • Operation Example:
  • Drag and drop component generation interface (list, form)
  • Configure distributed capabilities (such as "click the button β†’ send data to the car machine")
  • Publish to the mobile phone/car application market with one click

5. Future trends: "Evolutionary Blueprint" of the development modelπŸš€

  1. AI-assisted development
  2. Automatically generate ArkUI interface (upload design draft β†’ automatic code generation)
  3. Intelligently optimize distributed task allocation (such as dynamic scheduling based on device load)

  4. Zero Code Deployment

  5. The module is automatically adapted to all Hongmeng devices after compilation

  6. Real-time monitoring of application performance in the cloud, automatically triggering hot updates

  7. Atomization Service Development

  8. Single module can be published independently as "universal card"

  9. Cards can be called directly by other applications (such as weather cards embedded in calendar applications)

Summary: The "Three Rules" of the New Development ModelπŸ“Œ

  1. Module priority: The functions that can be split into modules are absolutely not coupled
  2. Declarative priority: Use ArkUI to describe "what" rather than "how to do it"
  3. Distributed Priority: When developing any function, consider "Can it be used across devices?"

Top comments (0)