Closing Preference screen is not calling Activity_Resume

PhilipK

Member
Licensed User
Longtime User
Hi, I have a service module that is doing background tasks. It has a widget front-end. When I touch an imageview on the widget, the preference settings page(coded in a main module) opens fine. On closing the settings page there is no activity resume call and so I can't handle any setting changes.
I have called the settings page from the service module:

Sub imgSettings_Click

myclickMain.standardFx(1)

StartActivity(Main.screen.CreateIntent)

rv.UpdateWidget

End Sub

But the following routine is not executed:

Sub Activity_Resume
HandleSettings
End Sub

Very odd. Help please?
 

Erel

B4X founder
Staff member
Licensed User
Longtime User
This is not so odd. In the usual case, when the preference activity is started from an activity there is an activity to return to. So the first activity is resumed. Instead of starting the preference screen you can start your own activity which would immediately start the preference activity (you can use CallSubDelayed to start the activity and call a sub that will start the preference activity).
 
Upvote 0

PhilipK

Member
Licensed User
Longtime User
Thanks. Been scratching my head, not getting anywhere.

I now get that you can launch the preference screen activity by writing a dedicated activity that will do it for you.

I have made a new activity called 'PreferScr' and pasted all of the code required to launch the preference screen..
Process_Globals
Dim manager As PreferenceManager
Dim screen As PreferenceScreen

Sub Activity_Create(FirstTime As Boolean)
If FirstTime Then
CreatePreferenceScreen
If manager.GetAll.Size = 0 Then SetDefaults
End If

Sub LaunchPreferenceScr

StartActivity(screen.CreateIntent)

End Sub

etc. etc.
In my service module, on clicking the widget 'button' :

Sub imgSettings_Click
StartActivity(PreferScr)

CallSubDelayed(PreferScr,"LaunchPreferenceScr")

End Sub

And it works!! Hurrah! Is that how it's done?

However, a minor detail:

When I close the preference screen it returns to a blank window and I have to press the back button again, to remove the window. I assume that this blank window is the 'PreferScr' activity still running? So I have put a variable within the 'Sub HandleSettings' to flag that the job has been done and test the flag as follows:

Sub Activity_Resume
If NewSettings Then
Activity.Finish
End If

HandleSettings

End Sub


It works fine but is that the right way to do it?

I feel I'm getting there and hopefully sensibly! Thanks for the life line.
 
Upvote 0
Top