Best App Updater For Android

3 views
Skip to first unread message

Ceola Roefaro

unread,
Jul 25, 2024, 2:28:37 AM7/25/24
to mongodb-csharp

I have a question regarding Android widgets and especially Android services. Here is what I want to do: On the phone the user should be able to add my widget to his homescreen. The widget gets its data from network.After reading some tutrials about this, I found out that the best approach would be to create a service that gets the data from network (TCP sockets) and then updates the widget constantly. That is done with ScheduledExecutorService which executes a Runnable in a certain interval. The Runnable will connect to a server, get the data and should update the widget).

When the first instance of the widget is added to homescreen, it will register a Broadcast Receiver that receives the ACTION_SCREEN_ON and ACTION_SCREEN_OFF intent action from Android OS.If ACTION_SCREEN_ON is fired, it will start the updater service, otherwise it will stop it. But I'm really unsure if that's a good approach because of the broadcast receiver lifetime.

best app updater for android


DOWNLOADhttps://urluso.com/2zN4Ci



In the updater service's Runnable, which is executed periodically by the ScheduledExecutorService and actually does the network stuff, I check via PowerManager.isScreenOn(), if the screen is on. If yes, I execute the network code, otherwise not. But what is when the device is in standby? Is this code executed then? What about battery drain here?

Is there maybe a "best practice" approach for what I want to do? I've read alot about the AlarmManager and that it is a very powerful tool. Can you schedule tasks with this in the way, that they are only executed when the display is on?

Your first solution (widget handling screen ON and OFF broadcasts) to the problem is the way to go. Start a new IntentService for a background communication to your application server. Once it finished, send your custom "Completed" broadcast with results and then handle it in your widget.

UPDATE As it is impossible to use screen ON/OFF broadcasts with a widget, I would probably use this (AlarmManager with an ELAPSED_REALTIME (not ELAPSED_REALTIME_WAKEUP) alarm) to schedule an (intent) service run. This way your service will not be scheduled when screen is off, but will run periodically when it is on. And if the delay between screen ON and OFF is more than the period it will run immediately on screen coming back ON.

As for your question about broadcast receivers lifetime, as said before, use IntentService for a long running task and then broadcast your results back from it. When you starting a service that call does not block so broadcast receiver will finish in a timely matter.

The ELAPSED_REALTIME approach could work I think, but strangly it is not for a small test app I created. Basically the test app is a widget and a IntentService. The widget only shows the current time, while the Intent Service gets the current time and sends a broadcast which the widget consumes in the onReceive() method and updates itself. The widget is of course a registered receiver for the custom broadcast action.In the onEnabled() method in the widget, I initialize the alarm for AlarmManager. Now some code:

So, I have tested this on my Nexus 4 running Android 4.2.1 and on an emulator with Android 4.0.4. In both cases the SimpleIntentService gets created and onHandleIntent() gets called every 3 seconds, even when I manually turn the display off.I have absolutely no idea why the AlarmManager still schedules the alarm, do you have?!

I figured that it has been a while since I posted what has been going on in the world of the Azure CI that I've been running. Sadly, I've not been able to spend as much time as I would like on the Swift work recently, but, I've made some improvements of note still.

PR Testing
Due to the consistent failures on Android and Windows, I have finally managed to setup enough infrastructure to be able to do PR tests on these builds as well (though they need to be manually triggered ATM). For those working on Swift who would like to occasionally run PR tests for Windows or Android, I'm happy to provide access to the Azure instance.

CI CI
I have been slowly migrating the rules from being pulled from Azure's mirror of the CI rules to GitHub directly. This makes it easier to manage the rules, but also enables a much easier approach to testing the CI: PR testing to do CI for the CI system itself. It does require a request from an authorized user, but does enable a way for others to be able to contribute more easily.

Android CI
The builds on Azure now are building the Swift standard library, libdispatch, foundation, and XCTest libraries for android across x86, x86_64, armv7, and aarch64. These are also pretty stable. I would like make further improvements to this to see testing added to this so that we can have more coverage.

Windows CI
Windows CI is still not in the state that I would like. I'm not a DevOps person, so it takes me quite some time to figure out the best way or even a way to achieve some of the functionality I would like to see. Currently, the builds are very repetitive, and do not really do a very good job of reusing the rules. Additionally, the MSI generation is slow and as a result does not occur as frequently as it should/could be done. I have ideas on how to improve some of this, but, would love some help with that.

One of the bigger things is that I have finally got libdispatch tests enabled on CI, so we should be able to track regressions better now, particularly since we finally have most of the tests working on Windows thanks to help from @adierking. I hope to see the work that @gmittertreiner has been helping with lead to similar benefits on Foundation, allowing us to run the test suite on the CI hosts as well.

In the mean time, I have managed to get the Windows SDK (@jrose, yes, we need to figure out the proper name for that) setup to build on x86, x86_64, ARMv7, and ARM64. Unfortunately, these builds have been failing due to issues with clang/LLVM that I need to look into still. The reported failures on the status page is due to the other architectures, the only current stable platform seems to be x86_64 (funny given that I had brought up x86 first).

ARM64: Variadic Function Validation Failure - I believe that my original checks for the variadic signature in C was overly strict for the MSVC behaviour. This is something easy to fix, I hope to be able to get to this soon

X86: Calling Convention Failure - clang fails to properly handle a __swiftcall__ function which is similar to stret, which results in the frontend asserting as the type does not have a copy ctor or a move ctor.

ARMv7: Missing CodeView Register Mapping - I have added the mapping for the register file to CodeView to enable being able to generate basic Debug Information for Windows ARMv7. However, that change hasn't been backported to the Swift fork since it ended up being less than a straight cherry-pick due to the extreme divergence between the top of tree and the fork. I am hoping that @dexonsmith, @Nicole_Jacque are able to improve the situation there soon.

I hope that I have covered most of the details, but, a lot of work is still going on to improve the experience for developers. There are lots of avenues for others to contribute. Additionally, I hope that these updates tend to be useful for others following the work to get an idea of where things stand.

4a15465005
Reply all
Reply to author
Forward
0 new messages