I am currently using Xamarin to develop an android application.
What is the best way to add an background service to my application. It must always run if the app is open or closed. And it must interact with the application database without opening it.
For example the application must check every 5 mins if it must send a notification this check is based on the data saved in the application itself
As you wrote in your question: Youe need to implement an Android service. You will find tons of tutorials and info sites in the web (just search for it).
First entry: Backgrounding with Xamarin
If you have some specific questions, ask here again.
For background service your best bet is Broadcast Receiver. Here you can read more about broadcastreceiver and for your second question of checking every 5 mins for updates can be done by using alarm manager along with broadcast receiver, this answer can guide you more
Related
In my Xamarin Forms application, I have a reminder feature built in that uses the cross platform plugin LocalNotificationsPlugin. On the Github page, the author states for Android that:
Currently, if the phone is re-booted then the pending notifications are not sent, you should save them out to settings and re-send on re-boot.
I have looked into how to doing this and it looks like I will need a broadcast reciever, triggered with a startup RECEIVE_BOOT_COMPLETED in my manifest file. This works well when I test, calling the show notification code when I reboot my device. However, it gets a little more complicated when I try implementing what I need.
I have to dependency inject my setting service to retrieve the currently active user. I then have to use an injected todo service to get all of their reminders. Both of these are normally done as tasks when the app is running. But to do this from a broadcast reciever, it appears I either need to uses GoAsync() (for operations lasting no more than 10 seconds), or start an IntentService. I'm not sure which of these would be more suited, but my guess is an IntentService as the user might have a lot of stored reminders.
I'm also trying to work out if our Security API will be able to return the currently logged in user if the app is not running.
Debugging is also a headache with this. Most guides online tell you how to reattach to a process when Android Studio or Eclipse is involved, but Visual Studio and Xamarin don't seem to have any way to do this.
So I suppose my main questions are: Am I right in using a Broadcast Receiver and possibly an intentservice?
Can a stored user be accessed even if the app is not running?
Are there ways to effectively debug when using Broadcast receivers after rebooting? I've tried reattaching the debugger and logging to the DDMS but haven't had much success in seeing what's going on.
A sample project trying to do exactly what I'm doing would be very helpful to me, but I'm struggling to find one that's comparable to my problem.
My understanding is to receive the data from push notifications while the app is in the background or not running, one need a service which will put the data somewhere where the app can get at them when it starts up or goes to the foreground. It appears that a common solution is to put the data into the app's Extras.
There are plenty of references for Java but my google-fu fails to find an implementation guide for Delphi.
Also useful would be information on how to "Stack" the notifications into a single notification.
I imagine one could write a single service which is triggered each time a notification arrives, and which then a) puts the data portion of the notification into the app's extras, and b) replaces the notification with a single stacked notification.
My question is "how does one write this service" - some template code would help, and tutorials or reference documents would be great.
FWIW this is for an app with a chat like feature where one doesn't want any notifications to get lost.
One thing at a time... here's a guide for implementing a service on Android.
Full disclosure: I've no idea how effective or useful it is or how complete (or otherwise) Delphi capabilities for Android services are since I use Oxygene for Android development (also Object Pascal but works very differently than Delphi, enabling me to make use of all those Java references).
The rest of your question seems more related to specific business/application requirements than a programming/technical problem, but if you run into specific issues you should consider asking questions about those separately.
I am currently developing an app which sends notifications at specific hours of the day. I can create an intent service, but I dont think it would work when the user is outside the app. So I need a service which works at specific times
Try to look here, I was using Firebase in my projects and it is super easy to implement...
Hey i wanna know if android apps are abble to perform some work like send data to there server accessing system tool and using all permissions it have requested for?
The scenario is, i install an app from google play successfully. I won't open that app. But i want it to contact its server and exchange some data and use all other permissions. Is this possible?
You can try it using broadcast reciever no need to run the app just regester for some broadcast reciever and wait for that to broadcast to your reciever and you can call whatever task you want in that reciever class... i will make it one and test it and post the github link in comment
No, the app needs to be run once in order for you to perform the specified actions, merely installing would not be enough.
I am trying to develop an app that should run in the background. I want my app to pop-up a message everyday at a particular time of day. As i read i will have to use 'Service' for this. http://developer.android.com/reference/android/app/Service.html#ProcessLifecycle This link shows an example. But where should my code for pop-up be? I dint understand well from the above link. Another question i have is will the app continue to run even after a reboot?
you can show a notification from the app to show pop up msgs, that is the best practice. though showing dialog is also possible. code will be in service only. see this link
And to keep your application running after reboot you will have to register for BOOT_COMPLETED broadcast and whenever you receive that broadcast, you will have to launch your service again. see this link