Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Skipping in Android Lifecycle methods

I am trying to understand the actual concepts of the lifecycle methods of an Activity.

I am focusing on only primary lifecycle methods as mentioned below

onCreate()
onStart()
onResume()
onPause()
onStop()
onDestroy()

Can someone please explain a scenario where we can skip a method and rest lifecycle works perfectly fine?

E.g. if I swipe up and kill the application, onPause() and onStop() methods will be skipped and only the onDestroy() method will execute.

like image 516
Tushar Srivastava Avatar asked Feb 16 '26 03:02

Tushar Srivastava


2 Answers

you cannot skip those methods, because when being implemented, they must call to their super class eg. AppCompatActivity - and when not being implemented, the will nevertheless be triggered within the super class. just see the documentation: Understand the Activity Lifecycle.

Activity Lifecycle

like image 176
Martin Zeitler Avatar answered Feb 17 '26 17:02

Martin Zeitler


Can someone please explain a scenario where we can skip a method and rest lifecycle works perfectly fine.

It never can happen unless you manually call finish(), say, in onCreate() which is quite pointless. If a lifecycle method is "skipped" by the system (and the only scenario when it happens is an app process being killed) the rest of the methods are also "skipped".

If I swipe up and kill the application, onPause() and onStop() methods will be skipped and only onDestroy() method will execute.

Again, it never can happen by the reason described above.

like image 24
Onik Avatar answered Feb 17 '26 19:02

Onik



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!