At the beginning I built an desktop application (WPF in .NET Framework) and Engine (Class Library in .NET Framework). Later I tried to built frontend for the Engine project in Xamarin.Forms/Xamarin.Android. I was suprised when I just added a reference to Xamarin project and everything worked fine.
The problem appears when I run my android application and block device using power button - application start to work 2-3 times slower. Even Task.Delay(1000) takes 1500-3000 ms to be executed.
I have internal timer in the Engine project and this problem causes time divergence between real-time and time inside Engine.
The Engine project is multi-thread project. It creates and destroys many threads during work.
What I have tried:
using WakeLock.Partial.
using Android.App.Service
disabled battery power optimization
all permissions for application
add application to "whitelist" in device settings(work in background, ignore battery
optimization options)
Application works fine on blocked device when the device is connected to power source.
Android Version: 10
Is it possible to keep CPU of android device running all time with full power? How to keep code exeuction at normal speed when device is blocked?
I have found the solution - WakeLock inside Foreground service.
Foreground service alone was not enough.
With this combination the Engine works with normal speed when device is locked without connection to any source of power.
Related
I have a problem with my hybrid app. This is android application, which large part is webview with JS app. Everything works generally great, but on some devices things going worser after running 'www protection' in antivirus on this device. To enable this option user need to turn on accessibility service of this antivirus.
After that users have a lot of skipped frames, really laggy app.
At the beggining of investigation what's going on, I want to see all device processes to see that really antivirus process consumes a lot of CPU. How can I do this? In Android Studio profiler I can see only threads from my app package. In developer options I can see only which services are enabled.
As the question is stating, I have a QT Quick application where I use QML for both the QUI and Backend. Now my application is quite straightforward and contains a timer that needs to keep counting down so I wanted to keep the screen on while the app is running.
The alternative is to use the android Wake Lock feature that keeps the app running if the screen is turned off. But the issue is that when I looked this up for Qt I found that the library called "Qt Android Extras" is available up until Qt 5+ but not Qt 6.
The reason being the timer pauses if the screen turns off and the timing is critical, thus it needs to keep counting no matter what.
This is my first Android app using Qt so I'm not familiar with what I should be doing, so what should I do or what am I missing?
I'm trying to build a limited-functionality Android system for our device, which needs to boot quickly, but everything we do seems to slow it down.
For example, our device has no camera, no bluetooth, no wifi, but turning them off wholesale in various /system/etc/init/*.rc files seems to actually slow it down, due to the interdependencies of Android. The services that are turned off end up restarting, or causing timeouts in Settings, for example.
(Android is on the device for its' UI, not for its connectivity abilities.)
Do you have any suggestions for how to do this? Surely Android for cars, TVs and tablets have had to deal with these issues before.
You did not specify what you did exactly, but if you tried to not start HAL services on startup they might just be started dynamically later. If you are using Android 8 or newer you could merge multiple HALs in one process. But I doubt that this will give you any significant speed-up.
Android does provide a guide on how to optimize boot times: https://source.android.com/devices/tech/perf/boot-times. However, you will notice that they focus on the bootloader, kernel, file system, SELinux, and parallelizing init. The elephant in the room is Zygote. It takes forever to start because it preloads the whole Android SDK.
From its history, Android did not care too much about startup times, because you typically do not restart Android. Instead, they rely on Suspend-to-RAM.
You should think about what you want to have your user experience early. Example: for Automotive Android, Google needs to support a rear-view camera that is available within two seconds after boot. They achieve that by a second, faster stack that provides first images before the application SDK is started and takes over. See https://source.android.com/devices/automotive/camera-hal
We need to create an app, which works for time tracking of the employees as well as location tracking.
We only want to program it for Android, but we don't have any Android skills.
Therefore phonegap came as a great alternative.
But there are several questions, to which I can't find a clear answer in the web.
If the phone is in standby mode, can the phonegap-app still send position data? Would this still be phonegap standard or do I need to use plugins?
the smartphones will be very simple and cheap. Is there a higher risk, that the phonegap application gets closed by Android to free memory then for a native app?
Alltogether, could it be recommend to invest the time to learn Android or would it be better to stay at our language JS?
It’s perfectly feasible to write a location tracking application using phonegap and have it a) work in a performant manner on low spec android phones and b) keep the app running in the background when the phone is in standby mode.
To keep the app running in the background on android, it’s necessary to acquire a partial wakelock (see android powermanager). In phonegap, you need to use a plugin to achieve this. On the plus side, there’s an existing phonegap plugin to do this. The downside is that in order to use a custom plugin, you will not be able to use the convenient phonegap build method to build your app, so will need to do the manual process via the Eclipse IDE, but this is not a great hassle to set up (see here).
In terms of your app getting closed because of android running out of memory, and also having it perform responsively on cheap, low spec devices, this won’t be a problem so long as you are careful to write your javascript code in an optimal way. I’ve implemented a location tracking app using phonegap which uses custom maps and in testing on older android devices including HTC Desire and HTC Wildfire, performance was acceptable and the partial wakelock worked - I had no problems with the app getting closed because of lack of memory.
I chose phonegap over native because I’m a web developer so Javascript is more convenient for me than having to start from scratch with Java and the android SDK, and also because I was able to use the same JS code base with appropriate plugins to produce the same app for iOS. Phonegap is able to access GPS hardware on the device and in testing outside I found the average accuracy to be between 4 to 8 metres depending on the device.
Hope this helps!
I've recently ported an application that is known to run with uptime of months (DIY Zoning Project) to Android (the accessory driver, the core process and the remote control). And, unfortunately, though techniques to keep running services alive were used (START_STICKY, startForeground()), sometimes the system^H service app just freezes up - until the user initiates an interaction with the service, after which it resumes normal operation. Most problematic is the fact that it is happening intermittently, and mostly after several days of uptime. The remote control works on the emulator for days at a time with no noticeable degradation, so the problem is most probably either in the service or in the accessory driver.
Currently, the system is targeted at API 10, so advanced service scheduling features are not available - that is, if they're related to the problem to begin with.
Now, what is the realistic way to debug and/or profile such a system? Remember, adb is not available for the Android hardware is connected to an ADK accessory.
Quite a late answer, however, did you try to use Wakelocks?
http://developer.android.com/reference/android/os/PowerManager.WakeLock.html
Possibly the system just hibernates the processor in some cases and it seems like "freezing up"