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

PhilipK

Member
Licensed User
Longtime User
Ok. Apologies, I have now looked at the Reply to Thread message menu bar!

Many thanks Erel
 
Upvote 0

Similar Threads

Replies
2
Views
654
Replies
15
Views
43K
D
  • Question
Android Question Activity_Resume run 2 times
2 3 4
Replies
65
Views
10K
Deleted member 103
D
Replies
175
Views
97K
Cookies are required to use this site. You must accept them to continue using the site. Learn more…