How to prevent user from closing application - Android 4.0.3
Asked Answered
A

5

5

So my question is: If is possible to prevent user from closing application.

Problem is because i can't hide action bar and i use tablet only for work time registration. So if someone press home button or back button is that not acceptable.

So i wonder if i could somehow handle onclose event?

Is it possible to open application in fullscreen (with no action bar)?

Amos answered 1/8, 2012 at 11:59 Comment(3)
And the down-votes are exactly why? This poster wants to create a kiosk-mode application for Android.Anergy
Try this stackoverflow search: stackoverflow.com/search?q=[android]+kiosk . I'm sure you'll find what you are looking for in there (or at least get some ideas)Anergy
@DavidWasser it might help if you as a subject-matter expert could identify a good close-as-duplicate target for this and future similar questionsSelfrenunciation
E
4

You cannot prevent user from closing application if he presses home button. That's the whole idea of it. Otherwise, you could leave user trapped in your app with no means to exit but to reboot it's device.

Extrinsic answered 1/8, 2012 at 12:3 Comment(4)
Yes that is exactly what i need. User traped in my application. Any idea how can i do this?Amos
@Michael - Your best bet is to have your own version of Android, then you can trap them.Override
That's not true. You can write a home-screen replacement which will get control when the HOME button is pressed. The poster wants to create a single-purpose device which has only a single application running. He isn't talking about an app for the market where random users can download it. Also, you don't need to create your own ROM to do this. That would be way more effort than it is worth.Anergy
he didn't state the purpose of his application, so I assumed it was "regular" android application and not a launcher appExtrinsic
E
4

Short answer is no.

Long answer is that you can make it quite difficult for the user to close you app. Some of the tricks that can be used are: reopen you app as soon as it closes , disable keys like back and power and finally disable the home button

Ecklund answered 25/8, 2012 at 2:55 Comment(0)
O
3

A user will always be able to close an application, otherwise there would be programs abusing it and causing problems, but there are steps you can make to better handle it being closed.

For example, if you have a remote service running that can check if the application is running, and there can be various ways to know, then it could fire off an intent to start the application again.

One way to know if a program is alive is to have it periodically call the service, basically doing a heartbeat check, and if it hasn't been called in some period of time, which should be 2 or 3 times larger than the expected check-in period, then fire off the intent.

There are other steps that may work, if you detect that the home button was pressed, but I would need to think through those steps. I think it depends on your expectations though, as trapping someone in your program would be really bad.

Override answered 1/8, 2012 at 12:5 Comment(4)
Yes trapping someone in app is really bad, but this tablet is there only for that app.Amos
There are perfectly valid reasons for trapping users in a single application. The Android tablet is a perfect device for installing in kiosks, or using in "kiosk mode", which is exactly this - the device becomes a single-purpose device (ie: it runs exactly one application and one application only). You don't need to go to the hassle of building your own ROM.Anergy
@DavidWasser - He wants to make certain that it will always be up, that it can't be killed, and the home button may be the problem, as something else could be started. But, that is why I suggested a possible solution, and a solution that may be correct when I think about it more (detecting the home button press). But, to never have it die would be difficult on a standard Android OS.Override
@JamesBlack We've successfully built kiosk-mode applications for Android tablets (without having a watchdog service restarting the app). I've never seen Android kill off a HOME-Screen replacement if it was the only app running on the device. Of course, your mileage may vary ;-)Anergy
N
2

try this...

//Remove title bar

this.requestWindowFeature(Window.FEATURE_NO_TITLE);


//Remove notification bar

this.getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);

Ref-> How to hide the title bar for an Activity in XML with existing custom theme

to prevent the user .......

@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
    if(keyCode==KeyEvent.KEYCODE_BACK || keyCode==KeyEvent.KEYCODE_HOME){
                    // pass some msg ......
        return true;
    }
    return super.onKeyDown(keyCode, event);
}
Nisa answered 1/8, 2012 at 12:6 Comment(3)
this.getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);Amos
Where did you put this code? In what method? It needs to go in onCreate() and it needs to be done BEFORE you call setContentView()Anergy
just ref. #2591536 this link to hide it.....Nisa
A
2

So here is my solution that works...

First you install trial version of SureLock application. Then in that app disable action bar. And thats it.

If you want to view again action bar you will need HideBar app

All of that works only on rooted devices...

Amos answered 2/8, 2012 at 13:9 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.