Hello All.
Just thought I would share some info with you. Most of our services in our apps would use
in the service create sub, where main_service is a long running background task, and has the notification object in it. This was used so android would not kill the service just launched if it was a long running service. Over the years methods have changed and API level have improved, so the app evolves, as it should.
We were testing on of our app on API 24 android 7 and noticed that when the phone was screen off and most probably sleeping when our service started, we use this code now
the screen would light up and then dim again. We did not see this on API 23 and below. So, after some further investigation it would appear that using the startforeground method under API 24 triggers a notification event to occur. @Erel could probably verify this.
Hope this info in of help.
Regards
John.
Just thought I would share some info with you. Most of our services in our apps would use
B4X:
Service.StartForeground(1,main_service.n1)
in the service create sub, where main_service is a long running background task, and has the notification object in it. This was used so android would not kill the service just launched if it was a long running service. Over the years methods have changed and API level have improved, so the app evolves, as it should.
We were testing on of our app on API 24 android 7 and noticed that when the phone was screen off and most probably sleeping when our service started, we use this code now
B4X:
Sub schedulecallback(timeToAlarm As Long)
Dim p As Phone
mod_functions.writelog("svc_ibeacon(), schedulecallback, API = " & p.SdkVersion)
If p.SdkVersion >= 23 Then
Dim srvAt As JavaObject
srvAt.InitializeContext
srvAt.RunMethod("StartServiceAtExactWhileIdle", Array(timeToAlarm, True))
Else
StartServiceAt("",timeToAlarm,True)
End If
End Sub
#If JAVA
//import android.app.Service;
import android.app.AlarmManager;
import android.app.PendingIntent;
import android.content.Context;
import android.content.Intent;
import android.os.PowerManager;
public void StartServiceAtExactWhileIdle(Long time, Boolean wakeUp){
AlarmManager alMan = (AlarmManager)getSystemService(Context.ALARM_SERVICE);
Intent intent = new Intent(this.getApplicationContext(), this.getClass());
PendingIntent penInt = PendingIntent.getService(this.getApplicationContext(), 1, intent, 134217728);
alMan.setExactAndAllowWhileIdle(wakeUp?AlarmManager.RTC_WAKEUP:AlarmManager.RTC, time, penInt);
}
#End If
the screen would light up and then dim again. We did not see this on API 23 and below. So, after some further investigation it would appear that using the startforeground method under API 24 triggers a notification event to occur. @Erel could probably verify this.
Hope this info in of help.
Regards
John.