start and stop a background application | developer.brewmp.com start and stop a background application | developer.brewmp.com

Developer

start and stop a background application

Forums:

Hi, All,

I am trying to doing some research on background applications, I create a module that has 2 applets in it. the main applet is a GUI applet and another is a background applet which doing some socket(network) functions. I call them 1(GUI APPLET) and 2(BACKGROUND APPLET), in MIF I set 2 hide applet, so user cannot start it in BREW manager.
I want to start 2 when 1 is started by user, and I also want to stop 2 when user select "stop 2" in munu of 1, I also hope when user select "start 2" in menu of 1, 2 can be restarted.
I have eventhandlings like below:
boolean App1_HandleEvent(IApplet * pi, AEEEvent eCode, uint16 wParam, uint32 dwParam) {
App1 * pme = (App1*)pi;
switch (eCode)
{
case EVT_APP_START:
...
//start 2
ISHELL_StartApplet(pme->a.m_pIShell, AEECLSID_APP2);
return(TRUE);

//post a event to notify 2 stop itself
case EVT_APP_STOP:
ISHELL_PostEvent(pme->a.m_pIShell,AEECLSID_APP2, EVTAPPLET,0,0);
return(TRUE);

case EVT_APP_SUSPEND:
return TRUE;
case EVT_APP_RESUME:
return TRUE;
...
case EVT_KEY:
//post event to notify 2 stop itself
if(wParam == AVK_3)
ISHELL_PostEvent(pme->a.m_pIShell,AEECLSID_APP2,EVTAPPLET,0,0);
//restart 2
else if(wParam == AVK_4)
ISHELL_StartApplet(pme->a.m_pIShell, AEECLSID_TWINAPP2);
else if(wParam == AVK_CLR)
return FALSE;
return TRUE;

default:
return FALSE;
}

return(FALSE);

}

//in event handling 2
boolean App2_HandleEvent(IApplet * pi, AEEEvent eCode, uint16 wParam, uint32 dwParam)
{

App2 * pme = (App2*)pi;

switch (eCode)
{

case EVT_APP_START:
pme->is_bg = TRUE;
...
ISHELL_CloseApplet(pme->a.m_pIShell, FALSE);
return(TRUE);

case EVT_APP_STOP:
//if 2 is set to background, put it to background
if (pme->is_bg) {
*((boolean*) dwParam) = FALSE;
}
else {
//something cleanup when stop
...
}

return(TRUE);
case EVTAPPLET:
//I hope STOP 2 instead of put it to background
pme->is_bg = FALSE;
ISHELL_CloseApplet(pme->a.m_pIShell, FALSE);
return TRUE;

return(TRUE);
}

}

return(FALSE);

However, I cannot really stop 2 when 1 post EVTAPPLET to 2, because EVT_APP_STOP of 2 are not reached after 1 post EVTAPPLET, and when 1 restart 2 calling ISHELL_StartApplet, the AEEClsCreateInstance is neither called, the resource in 1 is not clean up and realloc.

Could anyone please tell me how to REALLY STOP 2?
Any advice is appreciated.

What happens? Does the app go into the EVT_APPLET handler? Does ISHELL_CloseApplet() actually get called?

What happens? Does the app go into the EVT_APPLET handler? Does ISHELL_CloseApplet() actually get called?

Hi, Max,
Thank you for your time.
When 1 post EVTAPPLET, 2 reached eventhandling callback for EVTAPPLET, the is_bg is set to FALSE and ISHELL_CloseApplet is called, however, IT NEVER REACHED to APP_EVT_STOP, so 2 failed to release any resources.
and when 1 called ISHELL_StartApplet (starting 2), the AEEClsCreateInstance for classid of 2 is not called, and realloc resources of 2 is also failed.
were they the correct behavior?

Hi, Max,
Thank you for your time.
When 1 post EVTAPPLET, 2 reached eventhandling callback for EVTAPPLET, the is_bg is set to FALSE and ISHELL_CloseApplet is called, however, IT NEVER REACHED to APP_EVT_STOP, so 2 failed to release any resources.
and when 1 called ISHELL_StartApplet (starting 2), the AEEClsCreateInstance for classid of 2 is not called, and realloc resources of 2 is also failed.
were they the correct behavior?

Is this on the device or Emulator? If on the device, what build are you using?

Is this on the device or Emulator? If on the device, what build are you using?

Hi, Max,
Thank you for your reply.
This happened on emulator, I have not tried it on device yet.

Hi, Max,
Thank you for your reply.
This happened on emulator, I have not tried it on device yet.