Книга: Beginning Android
onCreate() and onDestroy()
onCreate() and onDestroy()
We have been implementing onCreate()
in all of our Activity subclasses in every example. This will get called in three situations:
• When the activity is first started (e.g., since a system restart), onCreate()
will be invoked with a null parameter.
• If the activity had been running, then sometime later was killed off, onCreate()
will be invoked with the Bundle
from onSaveInstanceState()
as a parameter.
• If the activity had been running and you have set up your activity to have different resources based on different device states (e.g., landscape versus portrait), your activity will be re-created and onCreate()
will be called.
Here is where you initialize your user interface and set up anything that needs to be done once, regardless of how the activity gets used.
On the other end of the lifecycle, onDestroy()
may be called when the activity is shutting down, either because the activity called finish()
(which “finishes” the activity) or because Android needs RAM and is closing the activity prematurely. Note that onDestroy()
may not get called if the need for RAM is urgent (e.g., incoming phone call) and that the activity will just get shut down regardless. Hence, onDestroy()
is mostly for cleanly releasing resources you obtained in onCreate()
(if any).
- Life, Death, and Your Activity
- Разработка приложений баз данных InterBase на Borland Delphi
- Open Source Insight and Discussion
- Introduction to Microprocessors and Microcontrollers
- Chapter 6. Traversing of tables and chains
- Chapter 8. Saving and restoring large rule-sets
- Chapter 11. Iptables targets and jumps
- Chapter 5 Installing and Configuring VirtualCenter 2.0
- Chapter 16. Commercial products based on Linux, iptables and netfilter
- Appendix A. Detailed explanations of special commands
- Appendix B. Common problems and questions
- Appendix E. Other resources and links