Auto: Showing the progress while doing a background call
up vote
3
down vote
favorite
We have an audio app and we want to add Android Auto capability to it. The app basically has a list of radio streams and the user can select which one to play.
In order to obtain the streams, I need to call a web service and obtain the streams, while that is occurring I wish to show an indeterminate progress at least on the hamburger menu like Spotify does when it's loading content.
At this moment if I have already downloaded the streams, on my MediaBrowserServiceCompat
when Auto calls onLoadChildren
my Result<List<MediaBrowserCompat.MediaItem>> result
object is populated with the MediaItems, if I don't have them I just send an empty array of MediaItems and call the API, once it has finished I call notifyChildrenChanged
on the Service and the list of streams appear, but until then I have a "No items" message.
I could not find on Android Developer site a way to set the children menu to show a loading and I could not find a sample app that does that. Does anyone know if there's way, maybe when onGetRoot
is called to let Auto know it has to wait before calling onGetRoot
and onLoadChildren
? I also tried calling the API then calling myself onGetRoot
but it did not work.
Thanks in advance.
android android-auto
add a comment |
up vote
3
down vote
favorite
We have an audio app and we want to add Android Auto capability to it. The app basically has a list of radio streams and the user can select which one to play.
In order to obtain the streams, I need to call a web service and obtain the streams, while that is occurring I wish to show an indeterminate progress at least on the hamburger menu like Spotify does when it's loading content.
At this moment if I have already downloaded the streams, on my MediaBrowserServiceCompat
when Auto calls onLoadChildren
my Result<List<MediaBrowserCompat.MediaItem>> result
object is populated with the MediaItems, if I don't have them I just send an empty array of MediaItems and call the API, once it has finished I call notifyChildrenChanged
on the Service and the list of streams appear, but until then I have a "No items" message.
I could not find on Android Developer site a way to set the children menu to show a loading and I could not find a sample app that does that. Does anyone know if there's way, maybe when onGetRoot
is called to let Auto know it has to wait before calling onGetRoot
and onLoadChildren
? I also tried calling the API then calling myself onGetRoot
but it did not work.
Thanks in advance.
android android-auto
I'm not sure exactly how Android Auto works, but couldn't your root View have a FrameLayout with your list and a loading symbol in it? By default, the list is invisible and the loader is visible. Then set the visibilities as needed?
– TheWanderer
Nov 8 at 16:12
Auto, for my knowledge, does not use custom layouts, and also, for what I need to do i don't require a custom layout, it only uses the methods on the Service @TheWanderer
– e_ori
Nov 8 at 16:14
add a comment |
up vote
3
down vote
favorite
up vote
3
down vote
favorite
We have an audio app and we want to add Android Auto capability to it. The app basically has a list of radio streams and the user can select which one to play.
In order to obtain the streams, I need to call a web service and obtain the streams, while that is occurring I wish to show an indeterminate progress at least on the hamburger menu like Spotify does when it's loading content.
At this moment if I have already downloaded the streams, on my MediaBrowserServiceCompat
when Auto calls onLoadChildren
my Result<List<MediaBrowserCompat.MediaItem>> result
object is populated with the MediaItems, if I don't have them I just send an empty array of MediaItems and call the API, once it has finished I call notifyChildrenChanged
on the Service and the list of streams appear, but until then I have a "No items" message.
I could not find on Android Developer site a way to set the children menu to show a loading and I could not find a sample app that does that. Does anyone know if there's way, maybe when onGetRoot
is called to let Auto know it has to wait before calling onGetRoot
and onLoadChildren
? I also tried calling the API then calling myself onGetRoot
but it did not work.
Thanks in advance.
android android-auto
We have an audio app and we want to add Android Auto capability to it. The app basically has a list of radio streams and the user can select which one to play.
In order to obtain the streams, I need to call a web service and obtain the streams, while that is occurring I wish to show an indeterminate progress at least on the hamburger menu like Spotify does when it's loading content.
At this moment if I have already downloaded the streams, on my MediaBrowserServiceCompat
when Auto calls onLoadChildren
my Result<List<MediaBrowserCompat.MediaItem>> result
object is populated with the MediaItems, if I don't have them I just send an empty array of MediaItems and call the API, once it has finished I call notifyChildrenChanged
on the Service and the list of streams appear, but until then I have a "No items" message.
I could not find on Android Developer site a way to set the children menu to show a loading and I could not find a sample app that does that. Does anyone know if there's way, maybe when onGetRoot
is called to let Auto know it has to wait before calling onGetRoot
and onLoadChildren
? I also tried calling the API then calling myself onGetRoot
but it did not work.
Thanks in advance.
android android-auto
android android-auto
edited Nov 8 at 16:26
asked Nov 8 at 16:10
e_ori
3501526
3501526
I'm not sure exactly how Android Auto works, but couldn't your root View have a FrameLayout with your list and a loading symbol in it? By default, the list is invisible and the loader is visible. Then set the visibilities as needed?
– TheWanderer
Nov 8 at 16:12
Auto, for my knowledge, does not use custom layouts, and also, for what I need to do i don't require a custom layout, it only uses the methods on the Service @TheWanderer
– e_ori
Nov 8 at 16:14
add a comment |
I'm not sure exactly how Android Auto works, but couldn't your root View have a FrameLayout with your list and a loading symbol in it? By default, the list is invisible and the loader is visible. Then set the visibilities as needed?
– TheWanderer
Nov 8 at 16:12
Auto, for my knowledge, does not use custom layouts, and also, for what I need to do i don't require a custom layout, it only uses the methods on the Service @TheWanderer
– e_ori
Nov 8 at 16:14
I'm not sure exactly how Android Auto works, but couldn't your root View have a FrameLayout with your list and a loading symbol in it? By default, the list is invisible and the loader is visible. Then set the visibilities as needed?
– TheWanderer
Nov 8 at 16:12
I'm not sure exactly how Android Auto works, but couldn't your root View have a FrameLayout with your list and a loading symbol in it? By default, the list is invisible and the loader is visible. Then set the visibilities as needed?
– TheWanderer
Nov 8 at 16:12
Auto, for my knowledge, does not use custom layouts, and also, for what I need to do i don't require a custom layout, it only uses the methods on the Service @TheWanderer
– e_ori
Nov 8 at 16:14
Auto, for my knowledge, does not use custom layouts, and also, for what I need to do i don't require a custom layout, it only uses the methods on the Service @TheWanderer
– e_ori
Nov 8 at 16:14
add a comment |
2 Answers
2
active
oldest
votes
up vote
1
down vote
accepted
OnGetRoot should return immediately, because it actually carries no content.
onLoadChildren though is where the content is loaded from, and it supports async loading on any content level. When your fetching the streams, don’t send an empty array of MediaItems before you call the API. Instead, fetch the streams from within onLoadChildren(). Call results.detach(), fetch the streams in another thread, then call results.sendResult when the content is available. The media content browser will show a progress spinner while waiting for the async sendResult call
Something like this will do the trick.
@Override
public void onLoadChildren(@NonNull final String parentMediaId, @NonNull final Result<List<MediaItem>> result) {
if (/* if music library is ready, return immediately */) {
result.sendResult(getChildren(parentMediaId, getResources()));
} else {
// otherwise, return results when the streams are ready
result.detach();
someMusicProvider.retrieveMediaAsync(new MusicProvider.Callback() {
@Override
public void onStreamsReady(boolean success) {
result.sendResult(...);
}
});
}
}
Works like a charm, thank you!
– e_ori
Nov 13 at 13:14
add a comment |
up vote
0
down vote
Would the use of ProgressBar be your answer? Simply add the view into any layout you require
<ProgressBar
id=“progressBar”
width=“wrap_view”
height=“wrap_view”
android:indeterminate=“true”
android:centreInParent=“true”
visibility=“gone” />
So once you have that in your layout, add a ProgressBar object and assign it on oNCreateView()
progressBar = findViewById(R.id.progressBar);
and simply as you begin the call request
progressBar.setVisibility(VISIBLE);
And on the callback for that webservice (if you don’t have one I recommend you create a quick “success/failure” callback) just call
progressBar.setVisibility(GONE);
Can't add a ProgressBar because Android Auto uses its own default ui
– e_ori
Nov 12 at 13:15
add a comment |
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
1
down vote
accepted
OnGetRoot should return immediately, because it actually carries no content.
onLoadChildren though is where the content is loaded from, and it supports async loading on any content level. When your fetching the streams, don’t send an empty array of MediaItems before you call the API. Instead, fetch the streams from within onLoadChildren(). Call results.detach(), fetch the streams in another thread, then call results.sendResult when the content is available. The media content browser will show a progress spinner while waiting for the async sendResult call
Something like this will do the trick.
@Override
public void onLoadChildren(@NonNull final String parentMediaId, @NonNull final Result<List<MediaItem>> result) {
if (/* if music library is ready, return immediately */) {
result.sendResult(getChildren(parentMediaId, getResources()));
} else {
// otherwise, return results when the streams are ready
result.detach();
someMusicProvider.retrieveMediaAsync(new MusicProvider.Callback() {
@Override
public void onStreamsReady(boolean success) {
result.sendResult(...);
}
});
}
}
Works like a charm, thank you!
– e_ori
Nov 13 at 13:14
add a comment |
up vote
1
down vote
accepted
OnGetRoot should return immediately, because it actually carries no content.
onLoadChildren though is where the content is loaded from, and it supports async loading on any content level. When your fetching the streams, don’t send an empty array of MediaItems before you call the API. Instead, fetch the streams from within onLoadChildren(). Call results.detach(), fetch the streams in another thread, then call results.sendResult when the content is available. The media content browser will show a progress spinner while waiting for the async sendResult call
Something like this will do the trick.
@Override
public void onLoadChildren(@NonNull final String parentMediaId, @NonNull final Result<List<MediaItem>> result) {
if (/* if music library is ready, return immediately */) {
result.sendResult(getChildren(parentMediaId, getResources()));
} else {
// otherwise, return results when the streams are ready
result.detach();
someMusicProvider.retrieveMediaAsync(new MusicProvider.Callback() {
@Override
public void onStreamsReady(boolean success) {
result.sendResult(...);
}
});
}
}
Works like a charm, thank you!
– e_ori
Nov 13 at 13:14
add a comment |
up vote
1
down vote
accepted
up vote
1
down vote
accepted
OnGetRoot should return immediately, because it actually carries no content.
onLoadChildren though is where the content is loaded from, and it supports async loading on any content level. When your fetching the streams, don’t send an empty array of MediaItems before you call the API. Instead, fetch the streams from within onLoadChildren(). Call results.detach(), fetch the streams in another thread, then call results.sendResult when the content is available. The media content browser will show a progress spinner while waiting for the async sendResult call
Something like this will do the trick.
@Override
public void onLoadChildren(@NonNull final String parentMediaId, @NonNull final Result<List<MediaItem>> result) {
if (/* if music library is ready, return immediately */) {
result.sendResult(getChildren(parentMediaId, getResources()));
} else {
// otherwise, return results when the streams are ready
result.detach();
someMusicProvider.retrieveMediaAsync(new MusicProvider.Callback() {
@Override
public void onStreamsReady(boolean success) {
result.sendResult(...);
}
});
}
}
OnGetRoot should return immediately, because it actually carries no content.
onLoadChildren though is where the content is loaded from, and it supports async loading on any content level. When your fetching the streams, don’t send an empty array of MediaItems before you call the API. Instead, fetch the streams from within onLoadChildren(). Call results.detach(), fetch the streams in another thread, then call results.sendResult when the content is available. The media content browser will show a progress spinner while waiting for the async sendResult call
Something like this will do the trick.
@Override
public void onLoadChildren(@NonNull final String parentMediaId, @NonNull final Result<List<MediaItem>> result) {
if (/* if music library is ready, return immediately */) {
result.sendResult(getChildren(parentMediaId, getResources()));
} else {
// otherwise, return results when the streams are ready
result.detach();
someMusicProvider.retrieveMediaAsync(new MusicProvider.Callback() {
@Override
public void onStreamsReady(boolean success) {
result.sendResult(...);
}
});
}
}
answered Nov 8 at 22:24
salminnella
2641313
2641313
Works like a charm, thank you!
– e_ori
Nov 13 at 13:14
add a comment |
Works like a charm, thank you!
– e_ori
Nov 13 at 13:14
Works like a charm, thank you!
– e_ori
Nov 13 at 13:14
Works like a charm, thank you!
– e_ori
Nov 13 at 13:14
add a comment |
up vote
0
down vote
Would the use of ProgressBar be your answer? Simply add the view into any layout you require
<ProgressBar
id=“progressBar”
width=“wrap_view”
height=“wrap_view”
android:indeterminate=“true”
android:centreInParent=“true”
visibility=“gone” />
So once you have that in your layout, add a ProgressBar object and assign it on oNCreateView()
progressBar = findViewById(R.id.progressBar);
and simply as you begin the call request
progressBar.setVisibility(VISIBLE);
And on the callback for that webservice (if you don’t have one I recommend you create a quick “success/failure” callback) just call
progressBar.setVisibility(GONE);
Can't add a ProgressBar because Android Auto uses its own default ui
– e_ori
Nov 12 at 13:15
add a comment |
up vote
0
down vote
Would the use of ProgressBar be your answer? Simply add the view into any layout you require
<ProgressBar
id=“progressBar”
width=“wrap_view”
height=“wrap_view”
android:indeterminate=“true”
android:centreInParent=“true”
visibility=“gone” />
So once you have that in your layout, add a ProgressBar object and assign it on oNCreateView()
progressBar = findViewById(R.id.progressBar);
and simply as you begin the call request
progressBar.setVisibility(VISIBLE);
And on the callback for that webservice (if you don’t have one I recommend you create a quick “success/failure” callback) just call
progressBar.setVisibility(GONE);
Can't add a ProgressBar because Android Auto uses its own default ui
– e_ori
Nov 12 at 13:15
add a comment |
up vote
0
down vote
up vote
0
down vote
Would the use of ProgressBar be your answer? Simply add the view into any layout you require
<ProgressBar
id=“progressBar”
width=“wrap_view”
height=“wrap_view”
android:indeterminate=“true”
android:centreInParent=“true”
visibility=“gone” />
So once you have that in your layout, add a ProgressBar object and assign it on oNCreateView()
progressBar = findViewById(R.id.progressBar);
and simply as you begin the call request
progressBar.setVisibility(VISIBLE);
And on the callback for that webservice (if you don’t have one I recommend you create a quick “success/failure” callback) just call
progressBar.setVisibility(GONE);
Would the use of ProgressBar be your answer? Simply add the view into any layout you require
<ProgressBar
id=“progressBar”
width=“wrap_view”
height=“wrap_view”
android:indeterminate=“true”
android:centreInParent=“true”
visibility=“gone” />
So once you have that in your layout, add a ProgressBar object and assign it on oNCreateView()
progressBar = findViewById(R.id.progressBar);
and simply as you begin the call request
progressBar.setVisibility(VISIBLE);
And on the callback for that webservice (if you don’t have one I recommend you create a quick “success/failure” callback) just call
progressBar.setVisibility(GONE);
answered Nov 8 at 16:31
Brandon
11018
11018
Can't add a ProgressBar because Android Auto uses its own default ui
– e_ori
Nov 12 at 13:15
add a comment |
Can't add a ProgressBar because Android Auto uses its own default ui
– e_ori
Nov 12 at 13:15
Can't add a ProgressBar because Android Auto uses its own default ui
– e_ori
Nov 12 at 13:15
Can't add a ProgressBar because Android Auto uses its own default ui
– e_ori
Nov 12 at 13:15
add a comment |
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53211708%2fauto-showing-the-progress-while-doing-a-background-call%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
I'm not sure exactly how Android Auto works, but couldn't your root View have a FrameLayout with your list and a loading symbol in it? By default, the list is invisible and the loader is visible. Then set the visibilities as needed?
– TheWanderer
Nov 8 at 16:12
Auto, for my knowledge, does not use custom layouts, and also, for what I need to do i don't require a custom layout, it only uses the methods on the Service @TheWanderer
– e_ori
Nov 8 at 16:14