I am trying to develop an application which will download some json strings(greetings) from server .As I am new to android,I don't know exactly how to do that.The application will have its own inbox which will be implemented through sqlite and system will download all the latest greetings(json strings) automatically from server and will put them in the inbox.So what is best approach for this,I mean should I use SERVICES or Async Tasks for it ???I want that whenever a new greeting comes to the server, my application should download it automatically without any user request and when user opens the inbox,it is uptodate.
Services are more appropriate to the use case that you have described here. services are meant to be used in the scenarios when you are not sure when the data will be arriving and you want to keep checking for it in the background without letting the user know that something is going on Asynctask on the other hand is more useful when u need to do some network dependent thing or something that will take time after a user clicks on something.The asynctask is just another way to show the user a proper waiting progress bar or something while the application is processing the user's request so that the user doesnt feel like the app is stuck. So SERVICES it is for your case.
if you want to update the database even if the app is not running you will need a service or a sync account
for services
http://marakana.com/forums/android/examples/60.html
for the sync adapter
http://developer.android.com/resources/samples/SampleSyncAdapter/index.html
I implemented something similar using a service
Related
I want to make an android app that will display mess menu of hostel. The menu will be changing every week so how can I change content of TextView once it is installed in user's phone .I considered WebView but I want better alternative . I think I need some cloud based service here . What are some good resources to achieve this.
Just do a Simple REST API and then every time you start your app call your api to retrieve the information, for example
yourdomaing.com/api/menu/getmenus should retrieve a Json with every item on menu.
You have plenty languages for making a simple rest api
check this related link
Examples of REST APIS
You can store your data (Text/Media) on firebase,It is very easy to start and then enable firebase offline functionality so that it is not required to download data on each launch of application.
Update data on firebase and add valueEventListener in your activity to get that data.
An alternative could be Firebase (by Google).
It's a free and real-time service. It allows you to change the content while the app is running. See "real-time database" and "A/B testing" in Firebase.
For example I expect this kind of situation: data in my application lost relevance and so it usless until update. And until update it have to show users some predefined message.
Is here any simple and free solution to this task?
Guess I can use some server to somehow send simple messages... but it sounds way too complicated.
If this is important I use Xamarin.
Update: main difficulty here is fact - my application can't in any way define if it's outdated or not. This may happen in random moment.
Although the requirement is not very clear I assume Update here means app update.
each time user launches app make call to an api on ur server to check if user needs to update app
If that returns true take user to a static view that says app needs update and redirects user to google play to install updates
If you want to avoid using a server, you should try Firebase (https://firebase.google.com/). More specifically, you should use Firebase Remote Config (https://firebase.google.com/features/remote-config/).
Define in a key-value pair of something like minimum_app_version_required in Firebase Remote Config. Every time user opens the your app, compare the values of app version and minimum_app_version_required that you are getting from Firebase console and show a dialog box accordingly. You can also change the value of minimum_app_version_required anytime you want.
Just set some internal flag. That when that situation occurs, you can set the flag to true and just edit whatever layout element you are using such as listView or any other element with your predefined messages saved in strings.xml. You can also build any custom pop up screen, depends how you want to show them. Let me know if you didn't understand or exactly how you want?
Need to implement versioning for this problem. To achieve this, you have to maintain a version number in server, this is the version number you app will have to save and use it to validate with server. If both are not same, then app will get the latest data from the server.
I'm developing an Android application , i have to develop an activity that contains a simple communications board .
The information that i want show are contained in a database , When the user started the activity the informations are downloaded , parsed and Showed to users.
Now i would implement a function That notify to the user When a new information is inserted in the db.
Now what that i don't understand is:
I need to implement a service that runs in background and polls the database and notify to the user when a information is inserted or can i use only the GMC (now FCM) ?
If i don't want use GCM there are another solution to do this ?
I have read some thread in stack overflow and there are different solution but i don't understand what is the best solution for my problem.
Speaking at a high-level, here's what I would do.
If I didn't want to use GCM then I would write my own service to make an http request to my backend web server to check if any new information is available. If any new info is received save it to my local Android database and refresh the app. I'd use Android's AlarmManager to start this service every so often (hourly, daily, whatever frequency I want).
For example, whenever someone "likes" your post in Facebook, you get a notification. You don't have to refresh your page to get the notification. Or whenever someone sends you a message in Whatsapp you immediately get it.
How do they implement that? Does it use Ajax to listen for database changes every second or so?
I want to build an Android application which should do something whenever the value of a remote database changes. Should I use a service to check for the database value every second and compare it to the previous value? Is this the best way to do it?
You could either setup a gcm service or use the native android service to hit your database at a fixed interval of time . GCM would be more efficient and would be recommended , if your app is an extensive real time sort of an app like a messenger or something
You should look into Google Cloud Messaging. But you will need a server to implement it.
https://developers.google.com/cloud-messaging/
I'm building an application for a website that requires login. I have already implemented functionality that allows the user to login and data is downloaded and displayed.
I have to use a service that will poll the server every half hour and check if new data is available. I have a few design issues and not sure what the best way to implement this is.
If the session id expires, how should I hande this in the service?
The user is able to manually update the application, which means the same data can be downloaded twice. How should I avoid this?
When the user updates it's done in a asynctask from the same activity. Should I switch this to be done in a service as well?
Ask user to log in again or cache the login details and do it automatically. Only you would know the best answer based on what you want the user experience to be.
If you can detect it is the same data then don't download it again. If you cannot, duplicating it would be probably unavoidable.
A service would work. You could also use an async task inside a retained fragment.
http://www.androiddesignpatterns.com/2013/04/retaining-objects-across-config-changes.html