Skip to content

Commit 8f2be4a

Browse files
committed
Activity lifecycle: Stop only the services on stop
On stop: stop only the Kolibri services by directly calling ServicesPlugin.STOP. On resume: if the Kolibri bus is already started, start the services. If not, transition the bus to the START state which should start the services too.
1 parent a5749a3 commit 8f2be4a

2 files changed

Lines changed: 12 additions & 3 deletions

File tree

src/kolibri_android/main_activity/activity.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ def on_activity_stopped(self, activity):
104104
# run after thsi one, so we need to keep track of the webview's
105105
# URL before switching to the loading screen.
106106
self._last_kolibri_path = self._get_current_kolibri_path()
107-
self._kolibri_bus.transition("IDLE")
107+
self._kolibri_bus.stop_services()
108108
elif self._kolibri_bus.state != "IDLE":
109109
logging.warning(
110110
f"Kolibri is unable to stop because its state is '{self._kolibri_bus.state}"
@@ -116,7 +116,9 @@ def on_activity_resumed(self, activity):
116116
if self._kolibri_bus is None:
117117
return
118118

119-
if self._kolibri_bus.can_transition("START"):
119+
if self._kolibri_bus.state == "START":
120+
self._kolibri_bus.start_services()
121+
elif self._kolibri_bus.can_transition("START"):
120122
self._last_kolibri_path = None
121123
self._kolibri_bus.transition("START")
122124
elif self._kolibri_bus.state != "START":

src/kolibri_android/main_activity/kolibri_bus.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,8 @@ class KolibriAppProcessBus(BaseKolibriProcessBus):
1616
def __init__(self, *args, enable_zeroconf=True, **kwargs):
1717
super(KolibriAppProcessBus, self).__init__(*args, **kwargs)
1818

19-
ServicesPlugin(self).subscribe()
19+
self._services = ServicesPlugin(self)
20+
self._services.subscribe()
2021

2122
if enable_zeroconf:
2223
ZeroConfPlugin(self, self.port).subscribe()
@@ -49,6 +50,12 @@ def is_kolibri_url(self, url):
4950

5051
return False
5152

53+
def stop_services(self):
54+
self._services.STOP()
55+
56+
def start_services(self):
57+
self._services.START()
58+
5259
def can_transition(self, to_state: str) -> bool:
5360
return (self.state, to_state) in self.transitions
5461

0 commit comments

Comments
 (0)