1

I am trying to develop a custom "lock screen".

The main issue I am facing is that the user can actually always exit my "lock screen" Activity simply by pressing the HOME button.

I know it is not possible to block or override HOME. I was wondering if there is a way to restart the same Activity when the user presses HOME.

I have tried to restart the activity from the onPause(), indeed the Activity restarts, but it takes some seconds to restart, so the "lock screen" is pointless.

Is there some way to restart the Activity immediately after Home is pressed?

Vadim Kotov
  • 8,084
  • 8
  • 48
  • 62
Lisa Anne
  • 4,482
  • 17
  • 83
  • 157
  • Take a look at my answer [here](http://stackoverflow.com/questions/16657300/disable-all-home-button-and-task-bar-features-on-nexus-7/16657359#16657359). I think that may hold what you are looking for. Maybe. – TronicZomB May 24 '13 at 14:21
  • @TronicZomB thanks! But what I need is to circumvent the HOME button to be pressed, not the BACK. BACK can be overridden, HOME not. So I am looking for an entirely different solution ! Thanks Anyway!!! – Lisa Anne May 24 '13 at 14:29
  • I have the BACK and HOME Buttons in that answer. In order to circumvent the HOME button you need to make your app a home launcher application. Just add the fourth snippet of code down to you manifest. However this will then cause your app to replace the home screen completely (it can be undone though). Other than that, there is no way to get around the home button. – TronicZomB May 24 '13 at 14:32
  • Hi @TronicZomB I have made my lockscreen the default home launcher, my problem is that the home button is now useless while the user is inside the phone. Is it supposed to be this way? or am I missing something? – isaganiesteron Jun 11 '14 at 00:54
  • 1
    @isaganiesteron That is what it should be doing. By making the application the default home screen, you are replacing the current Android home screen with yours, thus whenever they hit the home button it would go to your lockscreen, not the Android home screen. – TronicZomB Jun 13 '14 at 12:12
  • 1
    Thanks @TronicZomB I realized that eventually, silly me.. I solved this problem by launching the home launcher within my lockscreen whenever the user presses home. – isaganiesteron Jun 14 '14 at 01:03

1 Answers1

3

I had the same problem once and I created a Service that was running in the background. It had a TimerTask loop that ran every second and checked wether my LockScreenActivity was in the foreground. You can do that like this:

List<ActivityManager.RunningTaskInfo> runningTasks = activityManager.getRunningTasks(4096); 
    return runningTasks.get(0).topActivity.getClassName();

If my lockscreen wasn't in the foreground, I started it up/ brought it to the foreground again (make it singleTop in the Manifest).

TronicZomB's answer looks more sophisticated though.

fweigl
  • 21,278
  • 20
  • 114
  • 205