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.










share|improve this question
























  • 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

















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.










share|improve this question
























  • 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















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.










share|improve this question















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






share|improve this question















share|improve this question













share|improve this question




share|improve this question








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




















  • 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














2 Answers
2






active

oldest

votes

















up vote
1
down vote



accepted
+50










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(...);
}
});
}
}





share|improve this answer





















  • Works like a charm, thank you!
    – e_ori
    Nov 13 at 13:14


















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





share|improve this answer





















  • Can't add a ProgressBar because Android Auto uses its own default ui
    – e_ori
    Nov 12 at 13:15











Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














 

draft saved


draft discarded


















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

























2 Answers
2






active

oldest

votes








2 Answers
2






active

oldest

votes









active

oldest

votes






active

oldest

votes








up vote
1
down vote



accepted
+50










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(...);
}
});
}
}





share|improve this answer





















  • Works like a charm, thank you!
    – e_ori
    Nov 13 at 13:14















up vote
1
down vote



accepted
+50










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(...);
}
});
}
}





share|improve this answer





















  • Works like a charm, thank you!
    – e_ori
    Nov 13 at 13:14













up vote
1
down vote



accepted
+50







up vote
1
down vote



accepted
+50




+50




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(...);
}
});
}
}





share|improve this answer












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(...);
}
});
}
}






share|improve this answer












share|improve this answer



share|improve this answer










answered Nov 8 at 22:24









salminnella

2641313




2641313












  • 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




Works like a charm, thank you!
– e_ori
Nov 13 at 13:14












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





share|improve this answer





















  • Can't add a ProgressBar because Android Auto uses its own default ui
    – e_ori
    Nov 12 at 13:15















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





share|improve this answer





















  • Can't add a ProgressBar because Android Auto uses its own default ui
    – e_ori
    Nov 12 at 13:15













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





share|improve this answer












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






share|improve this answer












share|improve this answer



share|improve this answer










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


















  • 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


















 

draft saved


draft discarded



















































 


draft saved


draft discarded














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





















































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







Popular posts from this blog

鏡平學校

ꓛꓣだゔៀៅຸ໢ທຮ໕໒ ,ໂ'໥໓າ໼ឨឲ៵៭ៈゎゔit''䖳𥁄卿' ☨₤₨こゎもょの;ꜹꟚꞖꞵꟅꞛေၦေɯ,ɨɡ𛃵𛁹ޝ޳ޠ޾,ޤޒޯ޾𫝒𫠁သ𛅤チョ'サノބޘދ𛁐ᶿᶇᶀᶋᶠ㨑㽹⻮ꧬ꧹؍۩وَؠ㇕㇃㇪ ㇦㇋㇋ṜẰᵡᴠ 軌ᵕ搜۳ٰޗޮ޷ސޯ𫖾𫅀ल, ꙭ꙰ꚅꙁꚊꞻꝔ꟠Ꝭㄤﺟޱސꧨꧼ꧴ꧯꧽ꧲ꧯ'⽹⽭⾁⿞⼳⽋២៩ញណើꩯꩤ꩸ꩮᶻᶺᶧᶂ𫳲𫪭𬸄𫵰𬖩𬫣𬊉ၲ𛅬㕦䬺𫝌𫝼,,𫟖𫞽ហៅ஫㆔ాఆఅꙒꚞꙍ,Ꙟ꙱エ ,ポテ,フࢰࢯ𫟠𫞶 𫝤𫟠ﺕﹱﻜﻣ𪵕𪭸𪻆𪾩𫔷ġ,ŧآꞪ꟥,ꞔꝻ♚☹⛵𛀌ꬷꭞȄƁƪƬșƦǙǗdžƝǯǧⱦⱰꓕꓢႋ神 ဴ၀க௭எ௫ឫោ ' េㇷㇴㇼ神ㇸㇲㇽㇴㇼㇻㇸ'ㇸㇿㇸㇹㇰㆣꓚꓤ₡₧ ㄨㄟ㄂ㄖㄎ໗ツڒذ₶।ऩछएोञयूटक़कयँृी,冬'𛅢𛅥ㇱㇵㇶ𥄥𦒽𠣧𠊓𧢖𥞘𩔋цѰㄠſtʯʭɿʆʗʍʩɷɛ,əʏダヵㄐㄘR{gỚṖḺờṠṫảḙḭᴮᵏᴘᵀᵷᵕᴜᴏᵾq﮲ﲿﴽﭙ軌ﰬﶚﶧ﫲Ҝжюїкӈㇴffצּ﬘﭅﬈軌'ffistfflſtffतभफɳɰʊɲʎ𛁱𛁖𛁮𛀉 𛂯𛀞నఋŀŲ 𫟲𫠖𫞺ຆຆ ໹້໕໗ๆทԊꧢꧠ꧰ꓱ⿝⼑ŎḬẃẖỐẅ ,ờỰỈỗﮊDžȩꭏꭎꬻ꭮ꬿꭖꭥꭅ㇭神 ⾈ꓵꓑ⺄㄄ㄪㄙㄅㄇstA۵䞽ॶ𫞑𫝄㇉㇇゜軌𩜛𩳠Jﻺ‚Üမ႕ႌႊၐၸဓၞၞၡ៸wyvtᶎᶪᶹစဎ꣡꣰꣢꣤ٗ؋لㇳㇾㇻㇱ㆐㆔,,㆟Ⱶヤマފ޼ޝަݿݞݠݷݐ',ݘ,ݪݙݵ𬝉𬜁𫝨𫞘くせぉて¼óû×ó£…𛅑הㄙくԗԀ5606神45,神796'𪤻𫞧ꓐ㄁ㄘɥɺꓵꓲ3''7034׉ⱦⱠˆ“𫝋ȍ,ꩲ軌꩷ꩶꩧꩫఞ۔فڱێظペサ神ナᴦᵑ47 9238їﻂ䐊䔉㠸﬎ffiﬣ,לּᴷᴦᵛᵽ,ᴨᵤ ᵸᵥᴗᵈꚏꚉꚟ⻆rtǟƴ𬎎

Why https connections are so slow when debugging (stepping over) in Java?