Android Question Place a phone call and conserve focus on calling view.

tigrot

Well-Known Member
Licensed User
Longtime User
Hi everybody,
I need to keep a window on top and active as well. I must get camera preview events and those events are fired only in case the window with camera preview is in foreground.
Any way to be sure to keep the window on foreground and active all the times?

Ciao e grazie

Mauro
 

tigrot

Well-Known Member
Licensed User
Longtime User
This code (an activity with a simple service) seems to work:
The Activity module(called Main):
B4X:
#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)

B4X:
#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
 
Last edited:
Upvote 0

tigrot

Well-Known Member
Licensed User
Longtime User
This sample will call a number then switch back to the calling Activity view, with the call active in the background.

Main Activity:

B4X:
#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.
    Dim ph As PhoneCalls

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.
    Dim edittext1 As EditText
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 button2_Click
  servizio.timw.Interval=2000
  ToastMessageShow("Chiama",True)
  Dim num As String=edittext1.Text
  StartActivity(ph.Call(num))
 

End Sub
Sub Activity_Pause (UserClosed As Boolean)
  servizio.ridotto=True
End Sub

The service module:

B4X:
#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)
    timw.Interval=100
End Sub

Sub Service_Destroy
    timw.Enabled=False
End Sub

This small code snippet allows to place a call in background conserving focus on the calling activity.

Regards
Mauro
 
Upvote 0
Top