You are on page 1of 2

Remedios Mae F.

Busaing
Donita Rose Alvarado

BSIT 603

03 Hands on Activity 1

CODE:

from kivy.app import App

from kivy.uix.label import Label

from kivy.uix.button import Button

from kivy.uix.boxlayout import BoxLayout

class MainActivity(App):

def build(self):

layout = BoxLayout(orientation='vertical')

self.label = Label(text="Activity Lifecycle Demo")

layout.add_widget(self.label)

self.button = Button(text="Press Me", size_hint=(None, None))

self.button.bind(on_release=self.show_toast)

layout.add_widget(self.button)

return layout

def on_start(self):

self.show_toast("onStart()")

def on_resume(self):

self.show_toast("onResume()")

def on_pause(self):

self.show_toast("onPause()")
return True

def on_stop(self):

self.show_toast("onStop()")

def on_destroy(self):

self.show_toast("onDestroy()")

def on_restart(self):

self.show_toast("onRestart()")

def show_toast(self, message):

print(message) # For demonstration, printing message to console

# You can replace print statement with Toast message for Android

# Example for Toast: Toast.makeText(getApplicationContext(), message,


Toast.LENGTH_SHORT).show()

if __name__ == '__main__':

MainActivity().run()

You might also like