-2

I am creating an android app . This app will install on user's mobile . After starting the first time by user this app create soon DB and register some setting on my online server . So I am expecting during this process user will not able to close my application and all the required setting created comfortably . Is there any way to do this .

Thanks

Shaishav Jogani
  • 2,111
  • 3
  • 23
  • 33
Sourabh Devpura
  • 79
  • 1
  • 2
  • 11
  • 2
    NO. You can't. Whenever user press `Home` button your application goes in back stack and then easily closed when they kill back stack. – user370305 Feb 17 '15 at 18:11

2 Answers2

2

There is no way to prevent the user from closing apps, because that would make malware/spam apps too easy.

What you can do is use a Service to handle creating the database in the background, even when the app is closed.

0

To achieve what you want, you could override the onBackPressed method in the Activity, as well es the onKeyDown(int keyCode, KeyEvent event) method, when the keycode equals KeyEvent.KEYCODE_HOME. Though a) that is not the way Android apps are supposed to work and b) there may still be cases, where your app goes to the background or gets killed.

If that is critical four your app, I would rather do such a setup in a Service.

2mac
  • 111
  • 3
  • 1
    AFAIK you can't intercept KeyEvent.KEYCODE_HOME – Cruceo Feb 17 '15 at 18:16
  • I am pretty sure I habe used it before (though it was supposed to work only on one device and was not a store app), but just tried it out, and it does not seem to work anymore, maybe that has changed. Thanks for your hint! – 2mac Feb 17 '15 at 18:23
  • Just did a little bit of research to make sure, you might find this interesting :) http://stackoverflow.com/a/2080353/1426565 – Cruceo Feb 17 '15 at 18:35