Android application get killed after screen locked for some time - java

I am developing an Android application involving recording data in bytes into file in phone storage from an external device that is connected via Bluetooth. I need the application to continuously run for few days without stopping.
I have tested for a few hours and the recording works fine while screen is ON. But when the screen is locked for more than a few minutes,in some devices like redmi phones, when i open the app again , it gets restarted again after stopping my app.This case happens when app is minimized for a few minutes.
I have searched on internet and came to know that applications are killed by android system when it is running on onPause for a some time inorder to save memory.
I am not sure if it is reason behind of that but if there is any other reason, please let me know.
Android working is as follows,
Establish Bluetooth connection between external device and android app.
I am using NRF BLE_app_uart library to get thing done.
Receiving data in bytes from external device to phone through bluetooth.
This data bytes are added to static arraylist and using an external runnable thread read values from arraylist and write/append into external file using Outputwriter method.
Data byte are simultaneously plotted in graph from external thread.
The tested device is Redmi Y2 (Android O , 8.1.0).
The problem is that when device is locked for more than few minutes , it gets destroyed and restarted again.
My doubt about reason is whether it is memory problem or android system doing.
Actually app is expected to run for few days and I wonder how various fitness apps are working for days.

Related

get a location once in the background at any time Android Studio Java

I want to get the location of the device once when the service is running in the background (the tracker monitors the change in the database and then executes the code that should get the geolocation of the phone). I encountered a problem: the program receives location data when the application is running, but when it goes into the background, the location data stops being received in a few seconds. I tried all the codes and options that I could find, but everything stops working when the program goes into the background. For this I use AndroidStudio Java. So how do I implement this and is it even possible? Thanks.
On Android there are two types of Services- foreground and background. Background (the default) on modern Android are killed 2 minutes after your app is no longer in the foreground. Foreground services are kept for longer, require you to have a notification so the user knows you're tacking him (think of Uber and the notification you can't swipe away you get while its running), but can still be killed for resources if other apps need it. You cannot rely on any Service running permanently.
So the answer is going to be either Foreground Service, or its going to be a completely different architecture for your program. The second really depends on exactly when and why you want to get the location.
There are many limitations on getting on getting location in background, refer to this
Do you target API level 29 or up? if yes, have you add ACCESS_BACKGROUND_LOCATION permission in manifest? If this is not declared, app can only access location while in foreground.
Even after declaring ACCESS_BACKGROUND_LOCATION permission, app can only get location data a few time in an hour due to limitations. Maybe you can consider using foreground service instead to avoid such limitations.

How to make a worker to setvalue in Firebase Database when app is closed and internet recovered?

Now in my app, if I have persistence disk enabled... if I setvalue while offline and close app, the value sets only when I reopen it. But I want to set it when internet connection recovers. Any solution?
I use firebase for android studio with java.
You cannot keep your app always in sync with the Firebase servers, while the app is in the background because the Android OS will eventually close it in favor of other apps.
When you enable offline persistence, it means your app writes the data locally to the device so you can continue to work with it while offline, or even if the user or operating system restarts the app.
If you want to perform some actions while the app is in the background, you should consider using a service.

Android App shuts down while using the Native Camera App

I'm currently developing and maintaining an Android Legacy app, native in Java. The App has been growing slowly throughout the years and I think the original architecture design it falling a bit short.
The app opens the native android camera, and for some reason, it kills the process in background, perhaps due to lack of resources. I've tested different flows with the android profiler, and wasted a lot of time trying to pinpoint what its happening. The flow goes as this:
The app is filled with data, using a SQL DB and static variables, then at some point the user is required to use the native camera to retrive a photo, then return to the app and keep on with the process. Sometimes, the process dies while being in the native camera app, and when returning, all the data stored on the static variables are empty, thus crashing the app and restarting itself.
Using the Android Studio Profiler, I found that when the process dies, it prints this in the console:
2021-11-18 22:19:54.906 9177-9762/es.myapp I/PhenotypeProcessReaper: Memory state is: 400
2021-11-18 22:19:54.906 9177-9762/es.myapp I/PhenotypeProcessReaper: Killing process to refresh experiment configuration
2021-11-18 22:19:54.906 9177-9762/es.myapp I/Process: Sending signal. PID: 9177 SIG: 9
Does anyone has any idea of what is happening? What is PhenotypeProcessReaper?
I'm trying to write a class to save the states of all the data to be able to recover the app after the process, but in the mean time I would really appreciate some help. Thanks!

Android App that listens if other apps crash on device

Is it possible to have an App that works in the background and listens to when another app crashes on my device?
I want my app to notify my computer when it detects that the app I'm using on my device crashed or stopped. If so would what it need to listen too?
A very hacky way would be to write a native binary which monitored Logcat, upload the executable to your device using ADB and launch it using the shell account. Note that this is not an App though.
The Android shell user has enough privileges to view Logcat for all processes and perform network operations, so you could just scan Logcat for the tell-tale messages that indicate that an app has crashed, siphon out the stacktrace from Logcat and then send it over the local network to your PC.
This actually sounds like quite a cool idea. Might have a go at it building it myself :-)
I think you want to create Samsung's Smart App Manager . That track the crashes of all application and show notification to uninstall app or remove.
From Android doc : By default, the system assigns each app a unique
Linux user ID (the ID is used only by the system and is unknown to the
app). The system sets permissions for all the files in an app so that
only the user ID assigned to that app can access them.
Each process has its own virtual machine (VM), so an app's code runs
in isolation from other apps.
By default, every app runs in its own Linux process. Android starts
the process when any of the app's components need to be executed, then
shuts down the process when it's no longer needed or when the system
must recover memory for other apps.
Each and every android application runs in isolation from other apps. So any app can't track the crash log of other app.
The question is : How Samsung's Smart App Manager is doing.
I think samsung smart app only works with Samsungs devices. Root Permission is required to perform such type of action. Samsung's Smart App only have root permission in Samsung's devices.
If you are developing app for custom ROM or Rooted android device then you can otherwise you can't do.
When you upload your apk in the android developer console you have any options including errors options, then when the app crashed in some device they can send a report and you will can see it in de console...

Receiving audio and video on android over HDMI or USB connection

I am rather new to Android development but I wish to receive audio and video content on my phone from a pc. I am trying to record gameplay on my pc, and do not have the money to buy the hardware recorder, and I can not do screen capture and maintain acceptable fps.
What I had in mind was to send my screen and audio to my phone like a second screen, where my phone will handle the saving process, reducing cpu load on my pc. I don't think android phones can receive hdmi output, but I can do this with the USB via the android adb library "pull" command. However this requires that the file already be saved.
I can't seem to find any other way to do this, can anyone recommend a library I could use?
No. USBs are slow. And there is no way to transfer what's on your computer screen to your android device without first recording it on the computer itself and then having to pass through the slow USB device and then slowly writing it to your phone's hard drive. You'll be recording at a solid 0.5fps by then.

Categories

Resources