Call multiple rest service link at sametime in android - java

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 :)

Related

Multi-Part request in background

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

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

Android - Code design of notification feature

I am working on an Android social app. It contains notification feature such as when A send a friend request to B, B should later get a notification icon shows 1 friend request on App bar (not a toast).
In order to know if the user has a friend request or not, the app will need to periodically send HTTP request to my backend API query for any notification. This should be performed in background. I am not sure what is a good way of implement such a feature. Should I use a Android Service? or should I spin a thread by myself? How to design and implement this to make sure it won't drain the data and battery? If I want to add a toast feature later, how should I design the whole client side notification system to make sure its easy to add the toast functionality?
Code pointers or suggestions will be greatly helpful. Thank you!
Periodically sending web-requests to check whether the user has any notifications or not is very expensive task for battery life.
Rather I suggest to use Push Notifications. There are third-party libraries available for this. Also recently Google Cloud has started Google Cloud Messaging for Android which is powerful framework to sync data between devices for specific app on certain events.
http://developer.android.com/google/gcm/index.html
Please follow the link above for more information to use Google Cloud Messaging for Android.
Also please have a look at following framework. It may of your interest.
https://parse.com/tutorials/android-push-notifications
sending web-requests periodically is even more expensive task (for battery) when the internet is not available in the device.

How do I prevent youtube stop playback using Android API?

As far as I know, with the YouTube API for Android, the player automatically stops when it's out of view. For example, when the app is closed or when another view is positioned on top of the player.
But I've seen this application: https://play.google.com/store/apps/details?id=com.mixerbox.mixerbox that seems to have found a workaround for this. In this app, when you close it, the video doesn't stops and continues playing in the background.
Anyone know how this can be achieved?
To play only the audio of a YouTube video violates the YouTube API Terms of Service:
Your API Client will not, and You will not encourage or create functionality for Your users or other third parties to:
9. promote separately the audio or video components of any YouTube audiovisual content made available through the YouTube API;
For educational purposes take a look at the Services developer guide.
A Service is an application component that can perform long-running operations in the background and does not provide a user interface. Another application component can start a service and it will continue to run in the background even if the user switches to another application. Additionally, a component can bind to a service to interact with it and even perform interprocess communication (IPC). For example, a service might handle network transactions, play music, perform file I/O, or interact with a content provider, all from the background
The MixerBox app you mention most likely has a Service that it delegates the play back of the video's audio to when its' Activity's onPause() callback is executed by the system. That is how MixerBox allows you to navigate away from the application and you can still here the audio playing from the video.

background threading in android

I am a research student who just started the android programming for 3 weeks and I am trying to write an App which extracts data from accelerometer from the phone and writing it on my phone. My problem is that I would like to run my App (taking data from accelerometer) all time when the phone is up and running. What I mean is that my App has to run all time when somebody is calling, facebooking and so on. Is that possible? I would like to get some references.
What I mean is that my App has to run all time when somebody is
calling, facebooking and so on. Is that possible?
So for long-tasks you can use AsyncTask or Services. If you want to execute some task and it have to run also when its not connected with any Activity(for example Music player, RSS which still run also after release from memory by memory manager), you should decide to use Services and also you can combine Services with AsyncTask.
Services are strong tool but work with them is not trivial. You are able to execute only one Service in time and only one Service can running, one instance, one copy. This all is not free so you have to be careful because when you implement Service too dirty, it may cause premature exhaustion of battery.
There is more approaches how to start Services but you have to read some tutorial and guides.
I recommend to check this: Services, ServicesDemo - Using Android Services, Android Service Tutorial, Local Service | Android Tutorial for Beginners
Also have look at AsyncTask, Android Threads, Handlers and AsyncTask - Tutorial
You can use Services. Look here
If you want your activity of your app to be closed, but still a process should be running at background doing your desired work, then you can use Service, or IntentService (Use intent service, in place like, you want an update after certain period of time).

Categories

Resources