How can I make my program keep working in the background? - java

I can't really show anything here I think.
It's not a problem in my code I think.
What I mean is when I'm running my program directly from my android device, or when it's connected to the USB on my PC through android studio in debug mode, or regular running in all cases when my program is running and then I open a new app on my phone or if I just move to the whatsapp to type something when I want to get back to my program I see it was close. And I need to run the program over again.
How can I keep my program to be running all the time in the background so I can get back to it and no need to run it over again?

Related

Java Android Runtime.getRuntime().exec()

I'm working on an app where I want to run an android shell command using:
Process process = Runtime.getRuntime().exec("input keyevent 85");
This should start/stop the music player for me, and it works when I'm currently on my app.
The way I do it is to set a prepared intent beforehand at a certain time, so I can have the music playing in a few minutes.
However, it doesn't work when I have the app running in the background. The intents do print out my Log.i messages in Logcat, so I'm not sure where the problem lies. Perhaps it is a permission problem?
Turns out, using this method, the APK would have to be signed, the device rooted and the APP be placed in the directory of system apps.

Android continuous voice recognition

I am currently trying to implement android voice recognition for a research project that I am currently working on. I was able to follow a guide and I am able to correctly receive input but I want the phone to continuously look for input instead of telling me to try again after a while. I want to use it to control a moving robot connected to the phone meaning that I won't be able to physically touch the screen. Right now I made it so that if speech is recognized and converted then it immediately calls promptSpeechInput() again but I can't seem to find a way to do that when it runs out of time.

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

Java detect when user closes down the laptop screen?

I have a little program where i need to somehow detect when the user just closes down his/her laptop screen. So; not turning of the entire computer but rather just closing down the screen.
Ive got a chat program and i need to make the user go offline when the screen is closed. For some reason my current socket connection is still alive when i just close down the screen.
Any ideas?
You can give a look to that library :
http://www.codeproject.com/Articles/6590/PC-StandBy-Detector-for-Java-Apps
It is really simple to use and worked well for me. (Window only)

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.

Categories