Opening app from background Android - java

I have created an Android app that I am also running on BB10 devices. It has some functionality regarding call logs, but one of the most important functions is that the app has to open (assuming it's in the background currently) whenever a phone call has ended. Worded differently, it needs to foreground itself whenever a phone call has ended. I currently have it creating a dialog that opens within the app, but it will not appear until the app has been manually foregrounded. I do not have a requirement as to how it opens itself, but I do need a yes / no dialog to appear when it does.
Is there any way to have the app auto-open itself? Or is that not possible?

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.

How to refresh activity while not using the app?

I'm working with realtime database where I want my activities to run even no one is using the app.
swipeRefresh.setOnRefreshListener {
// code
binding.swipeRefresh.isRefreshing = false
}
From the above code, the user needs to swipe to refresh, I want it to be the same but in background and it does itself.
That means the activity is like a 'refresh' in the background every five seconds.
It's not possible to keep an app running while it's not being used. Android app processes will be killed by Android when the user is no longer using the app, and this can't be prevented. Android does this to save resources and allow other apps to run when they are being used. I suggest reading the documentation to understand how it works.
Your app should isntead simply query the database again when it's launched and rebuild the UI.

Restart App Overlay after unlocking Phone

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

Keep android app in foreground unless in in settings

I have an app for a customer (refer to it as "their" app). When "their" app is open they do not want users of the device to use any other apps.
The only way they want to get round this, is if i create a login page within the app, and from there you can go to the android settings page. If the android settings are accessed, then the user should be able to go anywhere they want, until "their" app is in the foreground again, then the device should be locked into using just that app.
If this makes any difference, "their" app is a cordova app. I dont think it will, but thought i would mention it anyway. Needs to work in android 5.0
Is this possible at all? What would i need to implement for this? A service and timer?
UPDATE
It is a tablet, so it will never ring.
If the user presses the Home button, nothing should happen as the app should stay in the foreground

Is there a way to put a running android app as the android device wallpaper?

In detail, I want to know if it's possible to take the output from a running Android app and pipe it to the to the background of the display. In other words, have the background wallpaper update itself dynamically.
No you can't do it this way. The reason is because Android starts your app with an activity (unless your app is just made up of services to run in the background for other apps to call). Whenever your activity starts, it comes to the foreground and receives user focus. The Android documentation states that if the user performs an action that starts another activity or switches to a different app, the system calls another set of lifecycle methods on your activity as it moves to the background. At this point, the activity is no longer visible.
The closest concept to what you are trying to do is a live wallpaper but that is a service and is a different paradigm.

Categories