Building the Mobile Apps of the Future: Exploring the Technology Journey of Android, iOS, and HarmonyOS

Comparative analysis of Android, iOS and HarmonyOS

In the field of mobile application development, Android, iOS, and HarmonyOS are three common operating systems. This article compares them and presents some related code samples.

Android

Android is a mobile operating system developed by Google and based on the Linux kernel. It has the characteristics of open source code and can run on various devices. Here is an example of a simple Android application:

public class MainActivity extends AppCompatActivity {
    
    
    @Override
    protected void onCreate(Bundle savedInstanceState) {
    
    
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        
        Button button = findViewById(R.id.button);
        button.setOnClickListener(new View.OnClickListener() {
    
    
            @Override
            public void onClick(View v) {
    
    
                Toast.makeText(MainActivity.this, "Hello Android!", Toast.LENGTH_SHORT).show();
            }
        });
    }
}

iOS

iOS is a mobile operating system developed by Apple Inc. specifically for devices such as the iPhone, iPad, and iPod Touch. It has an elegant user interface and a rich ecosystem. Here is an example of a simple iOS application:

import UIKit
class ViewController: UIViewController {
    
    
    @IBOutlet weak var label: UILabel!
    
    override func viewDidLoad() {
    
    
        super.viewDidLoad()
        
        let button = UIButton(type: .system)
        button.frame = CGRect(x: 100, y: 100, width: 100, height: 50)
        button.setTitle("Click", for: .normal)
        button.addTarget(self, action: #selector(buttonClicked), for: .touchUpInside)
        view.addSubview(button)
    }
    
    @objc func buttonClicked() {
    
    
        label.text = "Hello iOS!"
    }
}

HarmonyOS

HarmonyOS is a distributed operating system developed by Huawei, aiming to build an all-scenario smart ecosystem. It has a unified development framework and cross-device capabilities. Here is an example of a simple HarmonyOS application:

public class MainAbility extends AbilitySlice {
    
    
    @Override
    public void onStart(Intent intent) {
    
    
        super.onStart(intent);
        super.setUIContent(ResourceTable.Layout_ability_main);
        
        Button button = (Button) findComponentById(ResourceTable.Id_button);
        button.setClickedListener(new Component.ClickedListener() {
    
    
            @Override
            public void onClick(Component component) {
    
    
                Text text = (Text) findComponentById(ResourceTable.Id_text);
                text.setText("Hello HarmonyOS!");
            }
        });
    }
}

Summarize

Android, iOS, and HarmonyOS are three popular mobile operating systems, each with its own characteristics and advantages. Developers can choose the appropriate operating system for application development according to project requirements.

The above is a simple comparative analysis of Android, iOS and HarmonyOS, and shows some relevant code samples. Hope to help you!

Guess you like

Origin blog.csdn.net/weixin_46254812/article/details/132112025