Repeating Alarms vs Sync Adapter, which one should I use? - android

I'm developing an Android app whose basic behavior is to show the user some pieces of information every certain configurable period of time. Those pieces of information come from my own server, so the app requests the server for new information whenever it is needed. Its behavior should be something like Muzei.
And here comes my question, should I use Repeating Alarms to fire a Service that does the job of downloading the new information, or should I use a Sync Adapter?
I've been reading about both methods, but I'm not very sure about which one is the best solution.
Thanks in advance

Related

How can I update app content frequently?

I'm new to app development and I am soon going to be developing an app for a local charity.
The charity is a dog rescue charity and the app will display information about dogs available for adoption.
The content will obviously need to be updated frequently, even daily, which will obviously not work constantly updating the app via the relevant app stores. What is the most common way to deliver content to an app?
My thoughts on previous experience would be to create a REST API and deliver the content remotely. Would an app allow this? Is there a method more generally used?
Thanks in advance.
You can save all the information to show of each dog available to adoption in a database, then make the app retrieve all the data from it every n time.
I recommend you to use Firebase, it is cross-platform (includes Android and iOS), and I consider it really good when starting using databases.
Here you can find documentation for every supported platform, and easy examples on how to work with it.
Good luck with your project! :)
I see you don't have clear specification on how often to update the app content and technical capability.
Use JobScheduler
Syncing to the backend (via REST API)to fetch the data is a battery drainer & there is no use in syncing data on device which is about to die, I would prefer Jobscheduler which will intelligently act as per various environment criteria met like charging/idle.
There are several facilities available to help your app schedule work. These include:
AlarmManager
JobScheduler
SyncAdapter
Caution: Exponential backoff is enabled on job dispactchers/schedulers
For 24-hour logic check here

Android notification in realtime

I have a website that sends and receives documents. I was thinking of building an Android app that notifies the user if a new document has been received, and displays document details if the notification is clicked. It doesn't have to be in real time, it could update in interval of five minutes or something.
What is the best way to update the Android app of changes in the website? I'm new to Android and I'm not quite sure where to start. I've heard of Services, BroadcastReceivers and Alarms, but I don't know if those are the right ideas.
Update: How do I update my Android db from my web db within an AsyncTask in my BroadcastReceiver? I'm worried I might have a "leak error" which sometimes comes up with my AsyncTask.
You can try to implement GCM or as the above-mentioned, work with an AlarmManager or the more efficient JobScheduler (requires API level 21!). Avoid doing heavy work on a BroadcastReceiver. Instead use the Broadcastreceiver to receive Alarms and start a Service in background. You may also have a look to WakefulBroadcastReceiver which holds a WakeLock for you. The Service could GET data from your webservice by using a REST architecture and update it's local database. Retrofit is a powerful open source library for a REST architecture. If there are new database records, you can inform the user by a Notification. Don't forget to check basic things like not starting the Service if the device hasn't got a network connection or to stop the Service after the work has been finished. I personally recommend to learn the basics first and then go to advanced topics. Good luck and pleasure.

Is there a simple way to sync android app between devices?

I have a list I keep in SQL dB and would like to sync it with at least 2 android devices.
I tried reading into sync adapter and it seems very complicated and too much for syncing a list.
Is this my only option or there is a simpler option?
The problem is I am short in time. So I wouldn't like to start implementing a general and complicated solution when I can implement something more specific and simple. This app is for myself only so I'd like to keep it simple.
If you just want to sync a list you can create a web service (server side). Identify the business logic e.g. say you want to keep the union of two lists.
You can have sync implemented from server side using push notification or may be say once a day when the app comes in foreground. You can also have a alarm based syncing where you can schedule this process.
Then you may not need whole adapter stuff. You can just consume this service and sync your data. Just decide for yourself.

Android: Best way of handling continuous pulling from server?

To start of, i should mention that i'm a newbie in Android (Not that much experience in Java at all tbh), so be easy on me.
I am making an app that continuously pulls data from a server, and then returns data through a http post request. The question is, what is the best way to handle the actual pulling from the server? Should i be using AsyncTask or create another thread and let it run on that? Are there better methods for this purpose?
I will be pulling data every 5 minutes. (I am aware that this will drain the battery very fast, and i should definately be using Androids C2DM framework. But i have no experience in it before and i'm on a deadline, so this'll have to do until i have time to learn how to implement it.)
I'm grateful for any advice!
As an alternative to C2DM, you can do the persistent TCP connection between your device and the server. Then every 5 minutes your server can push a tickle to the device. Upon being tickled, the device can request the information via Http post.
Here is some sample code on how to do that.The connection stays open in a background thread even after the app has exited
Creating and Managing a persistent TCP socket: http://openmobster.googlecode.com/svn/trunk/cloud/android/connection/src/main/java/org/openmobster/core/mobileCloud/android/module/connection/NotificationListener.java
Full Disclosure: I am the Chief Engineer of OpenMobster and I wrote this code. Please feel free to use whatever you like or just get an idea if thats what you need
Thanks
Do you need to pull the data in background (even if your app is not "opened" and the android device is sleeping)? I suppose thats what you want because you mentioned C2DM. If so..the buzzwords are AlarmManager (with repeating time)/BroadCastReceiver and maybe NotificationManager to notify the user. With AlarmManager you schedule your events (every 5 minutes) and with BroadcastReceiver you receive those events and do what you want to do every 5 minutes :)

Updating the app at exactly midnight

Is there a way to cause my app to update itself at exactly midnight every night? I need the new content to be displayed on the app right when it hits midnight. I have an idea of how to accomplish this, but if it isn't in another thread and is in the onCreate and the app is running in the background next time it is opened it would just display the previous info and not the updated?
I could also use help accomplishing this same thing with iPhone as well.
I will clarify a bit. So all the information that is to be displayed on the app will be in the app already. I simply want the content (whats displayed) on the app to randomize and then display the new group of content only once per 24hours or at exactly midnight. Hope that makes it more clear.
Android:
You can set pre-determined times to update with AlarmManager
You can look at a snippet here: Android: How to use AlarmManager
iPhone:
With iPhone you probably have to download the content whenever you re-open the app.
Can't you just have the app update the content upon launch, or when entering the foreground in the appDelegate.
This question is very vague - but if I understand the requirements correctly you will need to serve the application's content dynamically via a content server (or some type of a CDN). In this case there could be various scenarios.
In the easiest possible implementation, you could have the application be powered by data (XML, JSON, etc...) from something like Amazon S3 and have logic within the application to know how to fetch the correct data depending on the current day.
This wouldn't be extremely difficult to implement, but it would require building some type of cross-platform framework that reads the same kind of data for each application.
Is the content available before midnight?
If so, can't you have the app download it in the background beforehand and then make it available exactly at midnight?
If not, there's surely going to be some delay anyway.
app can not update itself at least in iOS apps.

Categories

Resources