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
Related
I know that it is a real problem with running apps in background for different OEMs, but how can I solve this problem?
My app has a webview integrated from an online radio, everything is ok, but after 5 minutes (in locked screen mode), the player stop playing... I can configure my mobile settings, going to Apps, Special access, Optimize battery usage, search for my app and disable that button, but I win only 10 minutes (15 in total), and the app will stop again...
I found something about services, but I'm a really beginner, I don't understand why should I use a service to run in foreground... I have also a notification icon (+title+message) which is showing on display even if the mobile screen is locked. For my understandings, that means the app is running in foreground and in background. Can't figure out how to solve this.
I'm a beginner, but I want to go with this app in production (Google Play), and I want to be useful, not to be just another app...
I hope somebody will have the patience to respond on my issue. Thank you!
(At least some advice, what should I do...)
You need services to run in the background when your application is not visible to the user. Android automatically kills some apps especially when they are resource intensive. This can also be done by some antivirus software, task cleaners, memory cleaning apps etc.
You need to build your application around these challenges because users will not be required to optimize their settings for your application to run.
This services can be triggered by some android activity lifecycles. When you lock your screen, some life cycle methods like the onPause() and the onStop() could be called in your applications by default. You need to handle these events.
Services
A Service is an application component that can perform long-running operations in the background. It does not provide a user interface. Once started, a service might continue running for some time, even after the user switches to another application. You need to create a service that will perform the tasks you want and periodically update the call back in your application.
E.g. The app may fetch notifications from a remote backend and periodically show them to the user at the notifications panel.
Android activity life cycles
As a user navigates through, out of, and back to your app, the Activity instances in your app transition through different states in their lifecycle. The Activity class provides a number of callbacks that allow the activity to know that a state has changed: that the system is creating, stopping, or resuming an activity, or destroying the process in which the activity resides.
Within the lifecycle callback methods, you can declare how your activity behaves when the user leaves and re-enters the activity.
References
Android Services -> Learn about android services
Activity Life Cycles -> Learn about activity life cycles
Hi I am trying to make a chathead bubble, like the one facebook has, for an app in android studio. I have been able to successfully display the bubble using Overlay and make it a service which continues to run even after the app is closed (not killed). However when I open another app or if I dont use my phone for more than 10 minutes, the chathead bubble disappears, unlike Facebook's bubble. How can I go about making the bubble display on the home screen and other apps for a longer period of time(potentially forever)?
For context, I used https://www.androhub.com/android-floating-widget-like-facebook-messenger-chat-head/ to make the bubble, using a View and a Service.
Thanks in advance
Your app's service will get killed by the android system to save battery. There is no exact and easy way to do that. You have to implement multiple methods to do that.
Use Foreground Service(You may have already doing this but just in case if not.)
Ask for permission to restrict Battery Optimization.
In some devices like Xiaomi and Vivo, you need special permission to always run in the background ask for that.
Ask the user to lock the app in recent tab so it won't get killed by the system.
If you are implementing the service, override onStartCommand() and return START_STICKY as the result. It will tell the system that even if it will want to kill your service due to low memory, it should re-create it as soon as memory will be back to normal.
If you are not sure 1st approach will work - you'll have to use AlarmManager http://developer.android.com/reference/android/app/AlarmManager.html . That is a system service, which will execute actions when you'll tell, for example periodically. That will ensure that if your service will be terminated, or even the whole process will die(for example with force close) - it will be 100% restarted by AlarmManager.
I have an Android application written in Java that uses an Overlay Service to display a search bubble similar to Facebook chat-heads or One notes Overlay.
The problem I'm facing is that on my new phone (Samsung) (Android 9) overlays get terminated after around 5 minutes of the lock screen. The OneNote Overlay visibly restarts.
I tried to implement the same by checking if was terminated by the system, not the user.
I also found a Broadcast Receiver that calls a function when the phone is unlocked even when my application is in the background.
Here I get the following error:
Not allowed to start service Intent { cmp=com.[...]/.[...] }: app is in background
What can I do to go around that?
Do I have to "push" my app to the foreground, start the overlay, and move it back in the background? is that even possible?
I guess you are using Android 10. (Not sure though). In Android 10 there's a new restriction that prevents you from starting an activity from a background service. More information here: https://developer.android.com/guide/components/activities/background-starts
I have recently fixed the 'd:skin' problem in eclipse. I have recently started learning android programming. I want to test an application so i open up the AVD manager create an AVD and i click start it takes about 15 seconds for the bar to get from 0% to 100%. The Loading window closes and no Virtual Device comes up. No error message nothing. I am running a Mac with 4GB RAM.
You state:
The Loading window closes and no Virtual Device comes up.
It sometimes comes up after a long time. Eventually, it will probably come up. If it still doesn't, take these steps:
Restart ADB
Restart IDE
Restart Computer
Because you stated that the loading window does come up, it is probably going to show up. After it does, I'm going to assume it looks something like this:
So, if you're lucky, this thing will start in 5 - 10 minutes. If you're anything like I was, it will never start, and you'll give up and download GenyMotion instead. GenyMotion emulator will run in about 30 seconds. It is still laggy, but a lot better than the default android one.
Let me know if this helped! :)
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.