Closing application in Android - delay - java

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.

Related

android studio button sometimes doesn't work

I have a menu activity from which I want to go to the meat of my application. When I press the button to do so, it sometimes opens the main screen within a few moments, sometimes takes longer, and in many cases, doesn't work at all. In the case that it doesn't work, the button will usually work after clicking it again. I have used debug statements to determine that the button is (sometimes) not registering the clicks at all. What could be causing this?
I have this problem sometimes, this happens with me because my crappy mouse, and sometimes it is caused by the emulator which starts lagging with time and not recording my clicks properly, from time to time I just to wipe the data of the emulator to make work properly again.
One good solution to check if your doing things right, is to install your app in a real device and check if the button is working properly.

Creating a custom android shutdown system

So recently my phone was stolen and besides all the trouble I had with the lost files I was pretty angry about the fact that it didn't came to my mind to create an app for android that prevents easy stealing or to be precise that will act as a Trojan horse inside of the thief's pocket. So what i thought about is an application that kicks in whenever you're holding your standby button or whatever you usually do to shutdown your phone. This application then looks like the real shutdown menu and asks you to shutdown with a pin or without one and whenever you shutdown without the right pin the phone will actually fake shut down in a way where it is still transmitting GPS and connecting to the next transmission tower so it is easily locatable (by fake shutdown I mean a black screen and silent mode until you are repeating the same method you used to shut your phone down). So is there any way of creating an app that has a higher priority than the android shutdown system so a custom menu pops up whenever you're trying to shutdown your phone?
Your idea isn't entirely impossible for Android.
There is no way for an app to have a higher priority than the Android Shutdown menu. However, that doesn't mean there's no hope.
If you remember popular Alarm apps, they typically have a feature that prevent you from turning off your phone when the alarm rings. This is usually done by detecting that a Long Press of the Power Button is pressed and then dismissing the Power Off Menu.
You can look at this answer for how to do this: https://stackoverflow.com/a/53679477
However, this is just so you can dismiss Android's Power Off Menu so you can show your own Power-Off Menu.
Afterwards, with your idea of displaying a Black Screen and Silent Mode... there's actually four three problems.
Screen Backlight for non AMOLED screens
Status and Navigation Bars
Can't block a Forced Shutdown
Personally, during the early days of Android and my early years of Android development, I released an app with a similar idea (have the phone give off the illusion of being turned off, so there's a higher possibility of phone remaining on if stolen), but due to those four problematic areas, the app has been retired.
So I speak with experience in saying that:
A black screen doesn't play nicely with screens that require a backlight. Even at lowest brightness settings, a completely black screen will still easily be seen as on.
Android doesn't have a way permanently hide the Navigation and Status bars. The best you'll get is Immersive Mode, but this mode will cause the bars to temporarily appear if you touch the screen. Even if you use a Full-Screen Activity, swiping down or swiping up will still show these bars. I believe your only option for hiding both of these bars is Root.
There's absolutely no way to block someone from doing a force shutdown. This completely bypasses the Power Off Menu and it's simply unblockable. So while your app might block some thieves, it might not block the more paranoid ones.
Hopefully, my answer is enough to nudge you in the right direction for your app.

Store data locally on app close, not when put into background

I am working on an app that i want the user to be able to run it in the background, but i need to save some data whenever the app is completely closed. I have been looking at using SharedPreferences. I am having issues with onPause() and onStop() since those are called whenever the app is put in the background. I need to save data only when the app is completely closed and not when the user brings another app to the foreground and puts mine in the background.
That's not how Android works. You could be closed entirely hours from now. Or weeks. Or not at all and the user turns off the phone causing you to never save. The entire design of Android and its Activities is such that you should always be able to restore your state, and you shouldn't know or care that your app is being terminated. In fact there is no signal that an application is being terminated.
You could try doing it in onDestroy, but it isn't really a great idea. There's situations where onDestroy is not called.

How to not let the user exit my app?

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.

Android: Re-open app after X minutes of idling?

I need my app to open itself back up after a certain amount of minutes that the device has been idle. In other words, instead of the device going into sleep mode and going to a black screen, my app will open back up (assuming it's running in the background). Think of it as an "idle screen" app.
It's fairly simple in theory, but I just can't figure out if it's even possible.
Assuming you have some service running, you can reopen the application by using one of the methods described here Launch an application from another application on Android

Categories