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

有帮助吗?

解决方案

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

其他提示

The onPause() method from Activity are managed by the UIThread, the main thread of your App. So you can't call it programmatically. If you want to call onPause() method, you need to call another activity over your current Activity.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top