Mihael Meklav
Mihael Meklav

Reputation: 335

How to prevent user from closing application - Android 4.0.3

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)?

Upvotes: 5

Views: 9026

Answers (5)

PC.
PC.

Reputation: 7024

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

Upvotes: 4

Mihael Meklav
Mihael Meklav

Reputation: 335

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...

Upvotes: 2

Hardikgiri Goswami
Hardikgiri Goswami

Reputation: 514

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);
}

Upvotes: 2

James Black
James Black

Reputation: 41858

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.

Upvotes: 3

Tomislav Novoselec
Tomislav Novoselec

Reputation: 4620

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.

Upvotes: 4

Related Questions