Android – Service – Lifecycle, hook methods and start/stop a service – Part 2

Android – Service – Lifecycle, hook methods and start/stop a service – Part 2

You can read part 1 here. service hook methods onCreate() – The service is being created and this method is launched only one. It is used to initialize the service. onStartCommand() – The service is started because of startService(). This method is called every time intent is sent via startService() – only for started service onBind() – A client is binding to the service via bindService(). All the intent extras are not visible here. – only for bound service onUnbind() – is called when all clients have been disconnected via…

Android – Service – Lifecycle, hook methods and start/stop a service – Part 2 Read More

Android – Activity and lifecycle states Part 1

Android – Activity and lifecycle states Part 1

Activity is the most common component in Android app and the most crucial. It is usually used to display information to the device screen but there also times that you do not have to provide a user interface with an activity. To implement an activity you need to follow some steps: Extend the Ativity class Override selected lifecycle/hook methods, those at the picture above define other methods or nested classes needed to implement the activity update the AndroidManifest.xml file to include the activity so Android OS knows about it. Lifecycle…

Android – Activity and lifecycle states Part 1 Read More

Android Kotlin – Lifecycle class

Screenshot 20181223 164055

It is a class that has the information about the lifecycle of activity or fragment. This class allows other objects to observe its state. First, the class needs to implement a LifecycleObserver (1). The class also needs a Lifecycle object (29. Then you have to add an observer. (3) Then add an observer annotation to the method you need to be called according to the activity state. You can find more information here. Android Kotlin – Lifecycle class

Android Kotlin – Lifecycle class Read More

Android Kotlin – Fragment Lifecycle


The following picture shows how an activity affects a fragment Callbacks onAttach It is called once when the fragment is attached to the activity onCreate It is called when the fragment is created. Initialize variables, objects etc. onCreateView Here you must inflate the layout file. onActivityCreated Here write anything that requires the activity to exist onStart It is called before it is visible onResume The fragment is visible and has focus onPause It is called when the user is leaving the fragment onStop The fragment has no focus onDestroyView It…

Android Kotlin – Fragment Lifecycle Read More

Android Kotlin – Activity Lifecycle

Android Kotlin – Activity Lifecycle

Let’s start with the states: Initialized The starting state Created No focus and not visible Started No focus but visible Resumed Has focus and it is visible Destroyed It is destroyed and OS can removed it from memory Lifecycle callbacks onCreate It is called when the activity starts. Here you can initialize variables, inflate the layout file and everything else that needs to be executed only one time onStart It is called just before the activity becomes visible. Here you can add everything that needs to start before the activity…

Android Kotlin – Activity Lifecycle Read More