Brew background application development

Source: Internet
Author: User
OVERVIEW

Brew applications can be divided into three types: activated, suspended, and background applications. activated or suspended applications reside in the Application Stack, this stack is used by brew to manage ongoing applications. The top application in the stack is the active application. Only the application can interact with users through screen replacement or user events; applications are suspended to some extent under the current active application stack.
Since multiple applications may be suspended, developers should try to minimize the resources occupied by the suspended applications. Applications in the stack can be suspended or activated through suspend or resume.
In brew2.0, backend application development is involved. Background applications do not reside in the Application Stack; that is, they do not change the running status based on pending or activation events. On the contrary, once the background application is initialized and running, it is always running, and it is not affected by the user's direct user instructions.

Starting/ending start and end

When initializing background applications, it is also like other normal brew applications. It can be directly started by the BREW application interface, or started by other brew applications using the ishell_startapplet function.
To run a BREW application in the background, the BREW application must set the dwparam value to false when processing the evt_app_stop event. After the evt_app_stop event is processed, the BREW application will be run in the background. To change the background application to brew for normal use, you must activate the application by running the ishell_startapplet function.
As mentioned above, it is difficult to terminate a background application because they cannot directly accept any button events. Therefore, to end a background application, you must use either of the following methods: after the background application successfully executes a scheduled task, it terminates itself or ends the background application by sending events to other independent applications. You can use the following methods:

  1. Other applications send events through the ishell_sendevent or ishell_postevent functions (the ecode value is greater than evt_user) to notify the background application to end;
  2. The background application terminates the background application by using the ishell_closeapplet function after executing the task. According to the help instruction of the API, after activating the function that calls the parameter ishell_closeapplet (pishell, true), all programs in progress will be closed and the standby interface will be returned. However, when the application is activated, this operation does not affect the program outside the application stack;
  3. The application activates itself by calling the ishell_startapplet function, so that it can normally accept user events;

Suspend/resume suspension and recovery

Background applications reside outside the application stack, so they are not affected by the suspension and recovery time. The background application can only process the suspension and recovery time when it is activated. It can be activated by events sent by itself or other programs.

Event handling event processing

When the background application is running, it cannot accept button events. However, many background applications can use event processing to interact with other activated applications, so that the background applications can be controlled by curves. In this case, you can use the ishell_sendevent () or ishell_postevent () method to notify the background application to respond accordingly.

Limitations

The main limitation of background applications is that they cannot modify screen information and communicate directly with users unless activated. In addition, developers should pay attention to the limited resources of the background application runtime environment. This is extremely important for the background, because multiple backgrounds may run simultaneously. In addition, devices running background applications will require more power support, which may lead to a failure to enter the trusted mode;
Therefore, long-term background applications should avoid harmful effects on the battery life of the device. Some OEM manufacturers may limit the performance of background applications. For example, when running background applications, it cannot use socket or play a bell sound.

Examples instance

Assume the following applet structure: // assume the following application structure. Typedef struct _ bgapp {aeeapplet A; Boolean m_bgobg; // used to toggle whether to run in background mode, which indicates the status of the backend application .} Bgapp; Model event handling for a background application: // The event processing model switch (ecode) used in the background {Case evt_app_start: If (PME-> m_bgobg) ishell_closeapplet (PME->. m_pishell, false); // send applet to backgroundreturn true; Case evt_app_stop: If (PME-> m_bgobg) * (Boolean *) dwparam) = false; // set dwparam to run in BG, return true is run in the background; Case evt_user: If (PME-> m_bgobg) {PME-> m_bgobg = false; // make applet active, activate application... ishell_startapplet (PME->. m_pishell, aeeclsid_bgapp);} else {PME-> m_bgobg = true; // trigger evt_app_stop to send app to backgroundishell_closeapplet (PME->. m_pishell, false);} return true ;}

Applications can use the evt_user event to set the application as a background application or activate the application. These events can be sent by other applications through the ishell_sendevent () or ishell_postevent () functions. In this execution process, the evt_user event only serves to switch the application between the backend and the foreground. More complex behavior processing can be performed by detecting the value of the dwparam parameter, which is passed by the application distribution time. If the application is directly started by the BREW application manager, the initialization value of m_bgobg determines whether the application runs in the background.
 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.