How to not let the user exit my app? - java

Hi i need something to don't let users exit my app without pressing the button exit. Basicly if they use home or any other button the app can't exit. How can i make this? Im using android studio and im new to this language.

The only thing you can do is override the onBackPressed method but unfortunately, you can't stop the home button from closing the app unless the phone is rooted or something. But when you do close the app with the home button it is still in Android's memory which prevents cold starts the next time the user opens the app. I am not sure why the information would be helpful though.

Related

How can Take permission using an alert Box at just destroy the application in Android

I just want to show an alert box at just killing the application in android.
It's like a Notepad application, if we simply kill the app (on clicking the close button) then we get an alert box asking for save changes.
I just want to add same thing in my application.I have tried onBackPressed() and its working fine on clicking on Back Button. But I need same thing on closing the application.
There is now way to be sure if the app is being closed but you can place a check if the application is in foreground or not which is a better metric IMHO as this tells you when the user moved away from your application.
To check the ProcessLifeCycleOwner this will help you find state of process. You can check this Github sample or this stackoverflow question in how to use it.

Is there a way to detect when a popup window appears in Android

I started a project of a windows program that connects to an android phone and gives the user information
about it, so I want to display all of the popups that appere on the phone. to do this I need the app version of the program to catch them somehow and give me the name of the app that sent the popup and the popup's contant. is it possible?
it would be kind of security issue if any app could do that... you can try with AccessibilityService with some permissions for reading screen/running Activities and checking style of every Activity is this "popup", but note that some of them are just DialogFragments. So I doubt you can recognize "popups" this way in a reliable way. Look for AccessibilityEvent.TYPE_WINDOW_STATE_CHANGED for more info

Home button brings back to my app

I am making a car launcher application, which contains shortcuts to other apps, when i'm in another app i'd like to press the home button and go back to my launcher
So basically i need to override the home button outside of my app,the override has to work only when my app is opened in the background so when i close my app the home button will work as usual taking you to your default launcher
Can i implement something like this or i'm asking too much?
There is no way to intercept the home button on Android, unless you make your app the home screen. This is for security reasons, so that malicious apps cannot take over your device by overriding all the buttons that can exit. The home button is the one sure shot way to be able to leave any app.
In short, no it's not possible, and even if it were, it is a serious disruption in what a user expects out of an app's behavior.
If you go the route of making your app act be a replacement home screen you'll have to include in the install instructions for the users to set your app as the default launcher.
Then the home button would take them to your app. In order to get it to switch back to the default launcher when they are not in "car" mode would be a bit tricky but you could prolly achieve it with some sort of fork activity that checks if car mode is enabled if so go to your car mode launcher if not go to the default launcher (it gets trickier if the user already has a different 3rd party launcher) So essentially your app will always be the home screen app no matter if car mode is enabled or not, but if it is not then you manually start the "normal" home screen.

Closing application in Android - delay

I programmed a button into my android app that called the finish() method when I click it. But somehow it does not close until after a 5-6 second delay.
I am recording sensor values for a particular movement of the phone. The problem is when there is a delay after I close, it records those unnecessary values and the analysis is messed up.
So any idea why the UI takes so long to respond? I am very new to Android and I can't find this online. I don't do too much computation- as and when sensors change I record the value onto a file in the sdcard memory. Sometimes if I run the program for too long, it just crashes and I don't know why.
Please help! I would also like to know if there's a manual way to kill through the computer? something like Ctrl+C for DOS?
Is there a keyboard shortcut to close a running Android application?
There is no concept in Android of "close a running Android application".
The Esc key in the emulator behaves as the BACK button to (typically) close the current activity.
I have a button that I use to kill the application in my phone and that has a huge delay.
No, you don't.

How to lock android buttons/phone from code (screen lock)? [duplicate]

This question already has answers here:
Closed 11 years ago.
Possible Duplicate:
Lock the android device programatically
I have made a simple Android app with a pin-code/screen lock. The user have to write a password to lock the phone and then repeat it to unlock the phone. The problem is that the user still can press back, home (etc) to exit the app without writeing the code. How can I prevent this?
You can block the back button by overwriting dispatchKeyEvent() in your Activity class, and returning true if event.getKeyCode() is equal to KeyEvent.KEYCODE_BACK. But you cannot block the Home button from going to the home page.
I have heard of some trickery where you register your application as a receiver of the android.intent.category.HOME intent. This would cause the Android OS to load your activity if the user presses the home button. If you can get this to work, you could then load the "actual" home screen if the user has entered the correct password. This approach is likely to behave differently on different devices and Android versions, however, and it probably would do nothing to stop the Hold-Home task list from appearing.
The bottom line is the Android OS has been designed to prevent just the thing you are trying to do: an application should not be able to take control over the phone and prevent other applications (especially the Phone) from running.
It's my understanding that you cannot block the home key as it's a security feature that allows the user to always exit an app. Pressing home will not close the activity however.
the guys who created free "Toddler lock" apk somehow managed to did it - download and see for yourself :)
when you run it, it asks for permission to run as home app and you need to check the box "use as default". To exit from app, you need to press on all 4 corners of the screen. All the buttons but power one are locked. So there is a way for sure to do that!
he explains to users how it works here:
http://www.toddlerlock.com/3.html

Categories