Search code examples
androidonpauseactivity-lifecycle

Is it somehow possible to send Activity onPause() progragmatically?


I have done my research. It seems not possible.

I need my Activity to go onPause() programmatically from onResume(), click a button and go somehow onPause(), without using onKeyDown()...

I know, probably impossible... maybe somebody has some tweak for that, or maybe not.

Thank you anyway


Solution

  • There is no way you can "pause" Activity from it's code. You can either close it by calling

    finish()
    

    or start a new Activity that will take the foreground - then you'll get it paused, but that's not what you want.

    I have never done a lock screen myself. There is really not much information, the Android is not designed to have third party lock screens apk's, so it might get really tricky if it's possible.

    What I suspect you have to do is to call a Launcher to hide your Activity, you can try this

    Launching default android launcher programmatically

    If it won't work, you can look at the code by the links provided in that question's answer. Good luck!

    https://stackoverflow.com/questions/10864300/create-a-lock-screen-of-my-own