Multi-Part request in background - java

This is more a question of software that a programming question, so making a multi-part request making that with the app open makes the user wait a bit, I can do a background task but I'm trying to keep the app api in 21(Android), what do a make in app open or I make a background that works with the app close and send the values until the file is ended?

There is a lot of cases you can do.You can use: RxJava or Kotlin coroutines (if you use Kotlin). Also you can try to use Koltin flow (similar to rxJava) but it's experimental yet.
If you need to make requests to rest api one by one you can do it with coroutines. All you need it's:
Add "suspend" keyword to method
Start it on View Scope or somewhere else
For rest api calls I recommend using Retrofit. This library can deserialise responses to pojo (for example with GsonConverterFactory). Also you can use "suspend" there

Related

Background execution in Xamarin.Android

I want to execute some code in background in my Xamarin.Android app. For example, make a HTTP request and do some actions on server side, get a response and update UI.
So, should I really use Android specific components like AsyncTask, IntentService, etc for that? Can I just run my code in Task.Run? Are there useful methods in C#/Mono to achieve my purpose?
You should use the C# model of asynchronous programming, it is used extensively in most Xamarin applications. Basically, your methods return "async Task" objects, which you can then "await" without blocking the UI thread.
EDIT
I also found some related information specific to Xamarin.

Request caching OKHttp 3.o or any other solution

I am writing an application that requires end user to constantly send updates to our server. I generally use the OKhttom or httpURLConnec clients to make me api calls.
The api call is tied to a button click.
In case my end user has no internet access, is it possible that if he clicks the button to make the request. The request is cached and made later on automagically whenever internet is available?
I can think you can read the Android documentation here and choose the best option for you like:
GcmNetworkManager - docs
JobScheduler (only for API 21+) example
Evernote has released a library which already switch to the best implementation available for the device, i would suggest you to use this without doing everything from scratch: https://github.com/evernote/android-job

Firing events on Android and Desktop Java when a database changes

I'm currently trying to work out what technology I can use to fire events remotely when a database changes, a realtime database of sorts. There is both an android application and a desktop JavaFx app that will communicate via the same database. When the data is changed from the desktop side, I'd like Android to update its data, and vice versa when changes occur on Android. Is there any method to achieve this without polling the DB for changes regularly?
I looked into Firebase and it seemed perfect, but lacked a desktop java library. Similarly, I have experimented with Amazon AWS Lambda and DynamoDB, and I can get a Lambda function to fire when the DynamoDB table changes. I can't however find a way for the Lambda function to update the Android/Desktop application that the data has changed though.
The JavaFx desktop application is a requirement of the project.
Apologies if this isn't possible, or if I'm overlooking a well known platform for this issue. Any help would be greatly appreciated.
No you not need the process of polling to achieve your results. To answer the first question, first the most flexible and plausible approach would to built a middle ware to intercept any changes.
Create a script to fire events whenever the data base changes. Wether by a time interval.
Second create server, a real-time server to fire such events to any client.
Third, the java fx client can use native observable for such a task. However i proposed going with a common listener, a perfect choice would be socket.io, there web-socket implementation available for android and vanilla java. For android client, whenever a data is inserted , transformed etc , use a broadcast receiver(local) to fire events in the to notify the server. Or use the socket.io connection to send events. Thats pretty much it.
Firebase + Cloud Functions for Firebase sound perfect for your use case. If the matter is pure Java support for Firebase, rather than Android, you might want to check out this question Get Firebase to work with java, not Android

Call multiple rest service link at sametime in android

I have android music app which have multiple section in it like latest music upcoming music popular music etc. how i can implement multiple rest link on android app start to fill these section lists ?
Using retrofit or any 3rd party API that supports Rest interface consumption. If your sections are dependent on one another, make the request for next section in call back. Or if not dependent, may be use separate threads to invoke services and in each call back, render the response accordingly on the view. Without code, this is the only help I can provide :)

How to integrate the channel api into phonegap?

I have coded two servlet(using the channel api) on gae that could make a connection f.ex.: for a chat
As UI I will use JqueryMobile.
My questions are:
How to integrate the actions of the servlets into phonegap?
Should I use any additional libaries or is it possible via action="...\servlet"(RESTful communication).
Is there any best practice?
I appreciate your answer!
Channels API relies on custom javascript that is downloaded from AppEngine when browser opens the page: see javascript docs.
This custom JS code can potentially change when GAE version changes, so you can not embed it into your PhoneGap application. Also it possibly relies on browser-specific features, which is hard to check because it's a closed piece of code and it's internals are not explained.
If you need async notification, I'd suggest you use native push technologies available on PhoneGap.
Read the Channel API documentation. It's all there.
You probably want to add an API to generate a new token in case your connection times out. You also need to handle reconnection from the client in case you get disconnected (ie a socketerror event)

Categories

Resources