언어 설정

Menu
Sites
Language
Background Application - Best way?

Hey guys,

I would like my application to continue working in background. This involves a timer, sensor support and networking.

Currently I used the "widget" template which seems to stop all work once the screen goes black. (Gear S2)

I was able to force staying active by locking the screen to be active, but surely this is very power consuming. The perfect solution would be if the app would run even while the display is powered off.

Any help is welcome! Thanks in advance :)

Responses

12 댓글
Alex Dem

Hi,
Even If usual UI app (from Basic UI Application template) comes to background (after power key was pressed -> app_pause is called), timers etc will continue works. Is it not enough for your case?
Alexey.

Dominik Fehr

I've tried the same now with a Basic UI App template as you recommended. Same result, nothing works when screen goes off. Any sample code you could provide? I'm using 2.3.1 SDK btw.

In static bool app_create(void *data):

ecore_timer_add(10, testFunc, NULL);

static void vibrate(int duration)
{
     device_haptic_open(0, &vibHandle);
     device_haptic_vibrate(vibHandle, duration, 100, &vibEffect);
}

Eina_Bool testFunc(void *data)
{
    dlog_print(DLOG_FATAL, LOG_TAG, "I'm active");
    vibrate(1000);
    return ECORE_CALLBACK_RENEW;
}

As before, it works fine when the UI is active, aka the screen is active.

 

Dominik Fehr

Not the case here, anything seems to stop.

I'm using the debug out and vibration to confirm the timer works correctly. Once the screen goes black, it doesn't work anymore. If I re-activate it, it works as usual.

Part of code:

    /* Start timer for HRM */
    dlog_print(DLOG_FATAL, TAG, "Starting timer");
    ecore_timer_add(60, startHRMsensor, NULL);

Eina_Bool startHRMsensor(void *data)
{
    dlog_print(DLOG_FATAL, TAG, "Timer ON");
    sensorReturnCounter=0;
    sensor_listener_start(listener);
    return ECORE_CALLBACK_RENEW;
}

void on_sensor_event(sensor_h sensor, sensor_event_s *event, void *user_data)
{
    sensorReturnCounter++;
    sensor_type_e type;
    sensor_get_type(sensor, &type);
    if(type==SENSOR_HRM)
    {
        if(sensorReturnCounter<=150)
            dlog_print(DLOG_FATAL, TAG, "BPM: %i Counter: %i",(int)event->values[0], sensorReturnCounter);
        else
        {
            sensor_listener_stop(listener);
        }
    }
}

Alex Dem

Ok,
I 'll try to look at this. Looks like timer works, but sensors does not in case of display was off  for any app (If I understood you correctly)
Alexey.

Alex Dem

Also I have found similar topic:
Looks like it is common behaviour for mobile & wearable: https://developer.tizen.org/forums/native-application-development/tizen-accelerometer-sensor-usage
There is solution to use sensor_listener_set_option(listener, SENSOR_OPTION_ALWAYS_ON);
Alexey.

Dominik Fehr

Seems this solution ain't bulletproof either. Anyway only sensors won't help. I wonder why it works perfectly for web-apps with background-support enabled, but native apps are limited :/

Jeongsu Kim

Gear S2 goes sleep mode when screen is turned off. Then any processes are freezed. So you can't get the timer callback.

Instead of timer callback, you can use alarm api to run application later.

https://developer.tizen.org/development/tutorials/native-application/application-framework/application/alarm

But I think it's better not to run application frequently because it makes more power consumption.
And I recommend to add and run a service app instead of UI app.

Dominik Fehr

Yeah, but even service apps have the same problem that they can not run frequently by themselves.

If we could execute code without the display beeing active, it would'nt require that much power. But we are forced to actvate the display to execute anything except for web-apps which makes no sense, since web apps just can activate background-support. Everythign except vibration will work fine there even when display is off.

Jeongsu Kim

You can make Gear S2 not to go sleep state by device power api

https://developer.tizen.org/development/tutorials/native-application/system/device#power

But be CAREFUL!! If you lock power state and unlock it, it makes heavy power consumption.

Dominik Fehr

Yep, that's not a good solution either.

Required is running code while keeping the display off, to save battery.

Just like web-applications can do.

Jeongsu Kim

You can lock cpu only.

int error;
error = device_power_request_lock(POWER_LOCK_CPU, 0);

// do you job

error = device_power_release_lock(POWER_LOCK_CPU);

It mens display can be off but not the cpu. Your app can run while keeping the display off.

Dominik Fehr

Will try it now and give feedback here.

Any known comparison between power consumption this way versus power consumption web-app background?