سؤال

First of all, as I know and as I tested, Android OS basicly pauses activity when user clicks home button, and resumes activity when user comes back. But when user locks screen, it destroys activity and recreates when user unlock.

Why?! Is there any reasonable explanation for this attitude?

My problem is just about this attitude of Android OS, I need to prevent user locking screen while application is still running. Because I have a splash screen which lets user in after getting some data about user, and finishes itself. On second activity, I release user's info onDestroy. But if user locks screen on second activity, the system calls onDestroy and it release user's info.

How can I prevent that to happen?

هل كانت مفيدة؟

المحلول

I'm not sure you can prevent the screen from locking, but you could check if the screen is locked in your onDestroy (something like this or this). If it is, save data in a saveInstanceState bundle and retrieve it in onCreate...

Hope this helps

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top