This code (an activity with a simple service) seems to work:
The Activity module(called Main):
#Region Project Attributes
#ApplicationLabel: B4A Example
#VersionCode: 1
#VersionName:
'SupportedOrientations possible values: unspecified, landscape or portrait.
#SupportedOrientations: unspecified
#CanInstallToExternalStorage: False
#End Region
#Region Activity Attributes
#FullScreen: False
#IncludeTitle: True
#End Region
Sub Process_Globals
'These global variables will be declared once when the application starts.
'These variables can be accessed from all modules.
End Sub
Sub Globals
'These global variables will be redeclared each time the activity is created.
'These variables can only be accessed from this module.
End Sub
Sub Activity_Create(FirstTime As Boolean)
Activity.LoadLayout("1")
StartService(servizio)
End Sub
Sub Activity_Resume
servizio.ridotto=False
End Sub
Sub button1_Click
StopService(servizio)
Activity.Finish
End Sub
Sub Activity_Pause (UserClosed As Boolean)
servizio.ridotto=True
End Sub
And the module(name: servizio)
#Region Service Attributes
#StartAtBoot: False
#End Region
Sub Process_Globals
Dim ridotto As Boolean 'flag active when Activity screen is hidden
Dim timw As Timer
End Sub
Sub Service_Create
End Sub
Sub Service_Start (StartingIntent As Intent)
timw.Initialize("TIM",100)
timw.Enabled=True
End Sub
Sub TIM_Tick
If ridotto=True Then StartActivity(Main)
End Sub
Sub Service_Destroy
timw.Enabled=False
End Sub
After pressing home button the reactivation takes about 3 seconds, but if you press BACK it's instantly on screen again.
Maybe this is produced by different event activation by Android.
Ciao and thank you very much.
Mauro