IT博客汇
  • 首页
  • 精华
  • 技术
  • 设计
  • 资讯
  • 扯淡
  • 权利声明
  • 登录 注册

    [原]Hello Bada!详解之一:系统框架与生命周期

    lincyang发表于 2012-07-25 20:51:05
    love 0

    在Hello Bada!中演示了如何创建一个简单的Form项目,简单的UI中按下按钮显示Hello及弹出对话框。

    今天以此项目为基础,来详细讲解一下Bada项目最基本的知识。

    一、Bada系统的架构

    从Bada文档中祭出架构图:


    先来简单分析一下这四层架构。

    最底层是Kernel层,Bada同Android等一样,也是基于linux系统的,所以它的系统kernel就是linux 的kernel。官网上强调它是实时的系统。

    底层的上一层是Device层,负责内存、IO管理,安全管理,图形窗口和事件管理,数据协议、移动通信,音频视频等多媒体管理。这是很重要的一层。

    再上一层是Service层,主要是应用程序引擎,比如联系人和信息组件,与bada服务交互组件。

    最上层为Franmework层,我们应用开发都要在此层做了。它提供基础api,UI和图形api等。

    大家再来看看下图。


    这幅图就是大名鼎鼎的Android架构图,可惜不知为何在Android开发网上找不到了。

    对比两副图我们会发现,底层是一样的,都是linux kernel。

    而我觉得Bada的framework层=Android的framework层+libraries层。因为Bada的开发语言是C++,可以直接调用系统提供的库,而Android用java封装好api,用这些api来调用

    那些库函数。

    二、应用的生命周期

    在Android中,应用程序的生命周期是与Activity紧密相关的,而在Bada,机制是不同的。

    还是先看图再说。


    应用程序会经历四个重要的状态:应用程序初始化、在前台、在后台、结束。

    对应在程序中:

    bool  
    Helloworld::OnAppInitializing(AppRegistry& appRegistry)  
    {  
        // TODO:  
        // Initialize UI resources and application specific data.  
        // The application's permanent data and context can be obtained from the appRegistry.  
        //  
        // If this method is successful, return true; otherwise, return false.  
        // If this method returns false, the application will be terminated.  
      
        // Uncomment the following statement to listen to the screen on/off events.  
        //PowerManager::SetScreenEventListener(*this);  
      
        // Create a form  
        HelloworldForm *pHelloworldForm = new HelloworldForm();  
        pHelloworldForm->Initialize();  
      
        // Add the form to the frame  
        Frame *pFrame = GetAppFrame()->GetFrame();  
        pFrame->AddControl(*pHelloworldForm);  
      
        // Set the current form  
        pFrame->SetCurrentForm(*pHelloworldForm);  
      
        // Draw and Show the form  
        pHelloworldForm->Draw();  
        pHelloworldForm->Show();  
      
        return true;  
    }  
      
    bool  
    Helloworld::OnAppTerminating(AppRegistry& appRegistry, bool forcedTermination)  
    {  
        // TODO:  
        // Deallocate resources allocated by this application for termination.  
        // The application's permanent data and context can be saved via appRegistry.  
        return true;  
    }  
      
    void  
    Helloworld::OnForeground(void)  
    {  
        // TODO:  
        // Start or resume drawing when the application is moved to the foreground.  
    }  
      
    void  
    Helloworld::OnBackground(void)  
    {  
        // TODO:  
        // Stop drawing when the application is moved to the background.  
    } 
    可以看到,前台和后台的管理是在应用程序级别来控制的。而Bada中的Form只有初始化和结束两种状态,如下:

    result  
    HelloworldForm::OnInitializing(void)  
    {  
        result r = E_SUCCESS;  
      
        // TODO: Add your initialization code here  
      
        // Get a button via resource ID  
        __pButtonOk = static_cast<Button *>(GetControl(L"IDC_BUTTON_OK"));  
        if (__pButtonOk != null)  
        {  
            __pButtonOk->AddTouchEventListener(*this);  
            __pButtonOk->SetActionId(ID_BUTTON_OK);  
            __pButtonOk->AddActionEventListener(*this);  
        }  
        //Get a label  
        __pLabel = static_cast<Label *>(GetControl(L"IDC_LABEL1"));  
        return r;  
    }  
      
    result  
    HelloworldForm::OnTerminating(void)  
    {  
        result r = E_SUCCESS;  
      
        // TODO: Add your termination code here  
      
        return r;  
    }  





沪ICP备19023445号-2号
友情链接