In android system, activity gets destroy in two scenarios.
1. When user press back button or write code in activity to destroy itself.
2. When activity is currently in paused/stopped state and it is not used in for a long time and current foreground activity requires more memory or resources.
Android system forcibly killed that activity and store it’s all member variables values in a bundle. If user destroy activity according to his/her wish then it doesn’t matter but if android system kills that activity without knowing to user, it may lead to app crash. To avoid such a situation programmer should use smart trick. For programmer it is necessary to implement that trick in his/her coding.
He/She should use onstop() callback method to release all occupied system resources and let the activity to use those resources and also implement onSaveInstanceState() callback method to store all member variables values into android system’s bundle.
When activity recreates itself then data can be recovered by that bundle. It will help to programmer to regain data in case when android system kills your activity. Through this smart trick programmer can avoid accidental app crash and also can make it to more effective in such accidental cases.
Related Posts...
GeneralTechnologies
Dec 12th, 2024
Technology is advancing at an unprecedented pace, reshaping industries and redefining the roles of professionals. As we approach 2025, staying ahead of the curve requires understanding emerging trends and their […]
Read more
Dec 10th, 2024
As 2024 comes to a close, it’s the perfect time to reflect on the remarkable technological innovations that have shaped the year. From advancements in Artificial Intelligence (AI) to the […]
Read more
Sep 26th, 2024
Learn how AI chatbots are transforming e-commerce by providing seamless customer support, automating tasks, and enhancing the shopping experience for users.
Read more