How to make the fragments load data from a service even before they are being displayed in the main activity?












0















My MainActivity is loading a fragment (there are 3 in total, controlled by a BottomNavigationBar). Each fragment receive data from LocalBroadcastManager, which is sent from an AsyncTask (since it need to do some network tasks), which is initialized from NotificationListenerService (it gets some music information).



Initially I loaded all the views directly into MainActivity, and they worked well, but since they are three different types of information, I decided to separate them into fragments. Now, only the fragment that is being showed get the data. If I switch to another fragment, it doesn't show anything until NotificationListenerService initialize the tasks again (it only happens when music state is changed). And if I return to the fragment that was showing the data, now it doesn't show it too.



Here is the code from one of my fragments (the three ones follow the same estructure):



String lastFmResults;
String lastFmKodes;
String lastFmDescriptions;

LinearLayout lastFmCards;

@Nullable
@Override
public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.fragment_last_fm, container, false);

lastFmCards = (LinearLayout) view.findViewById(R.id.last_fm_cards);

LocalBroadcastManager.getInstance(getContext()).registerReceiver(broadcastReceiverLastFm, new IntentFilter("LastFM"));

return view;
}

private BroadcastReceiver broadcastReceiverLastFm = new BroadcastReceiver() {
@Override
public void onReceive(Context context, Intent intent) {
Bundle extras = intent.getExtras();
lastFmResults = extras.getStringArray("values");
lastFmKodes = extras.getStringArray("names");
lastFmDescriptions = extras.getStringArray("descriptions");

updateLastFmCards();
}
};


And here is my MainActivity:



ColorsFragment colorsFragment;
LyricsFragment lyricsFragment;
LastFmFragment lastFmFragment;

BottomNavigationView bottomNavigationView;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);

if (!isNotificationServiceRunning()) {
startActivity(new Intent("android.settings.ACTION_NOTIFICATION_LISTENER_SETTINGS"));
}

colorsFragment = new ColorsFragment();
lyricsFragment = new LyricsFragment();
lastFmFragment = new LastFmFragment();

bottomNavigationView = (BottomNavigationView) findViewById(R.id.bottom_navigation);
bottomNavigationView.setOnNavigationItemSelectedListener(menuItem -> {
Fragment fragment = null;

switch (menuItem.getItemId()) {
case R.id.nav_colors:
fragment = colorsFragment;
break;
case R.id.nav_lyrics:
fragment = lyricsFragment;
break;
case R.id.nav_last_fm:
fragment = lastFmFragment;
break;
}

getSupportFragmentManager().beginTransaction().replace(R.id.fragment_container, fragment).commit();

return true;
});

getSupportFragmentManager().beginTransaction().replace(R.id.fragment_container, colorsFragment).commit();
}


I expect the fragments will load the data sent to them even though they are not yet being displayed in MainActivity.










share|improve this question























  • Add the 3 fragments at the same time and then just control its visibility

    – cutiko
    Dec 30 '18 at 18:09
















0















My MainActivity is loading a fragment (there are 3 in total, controlled by a BottomNavigationBar). Each fragment receive data from LocalBroadcastManager, which is sent from an AsyncTask (since it need to do some network tasks), which is initialized from NotificationListenerService (it gets some music information).



Initially I loaded all the views directly into MainActivity, and they worked well, but since they are three different types of information, I decided to separate them into fragments. Now, only the fragment that is being showed get the data. If I switch to another fragment, it doesn't show anything until NotificationListenerService initialize the tasks again (it only happens when music state is changed). And if I return to the fragment that was showing the data, now it doesn't show it too.



Here is the code from one of my fragments (the three ones follow the same estructure):



String lastFmResults;
String lastFmKodes;
String lastFmDescriptions;

LinearLayout lastFmCards;

@Nullable
@Override
public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.fragment_last_fm, container, false);

lastFmCards = (LinearLayout) view.findViewById(R.id.last_fm_cards);

LocalBroadcastManager.getInstance(getContext()).registerReceiver(broadcastReceiverLastFm, new IntentFilter("LastFM"));

return view;
}

private BroadcastReceiver broadcastReceiverLastFm = new BroadcastReceiver() {
@Override
public void onReceive(Context context, Intent intent) {
Bundle extras = intent.getExtras();
lastFmResults = extras.getStringArray("values");
lastFmKodes = extras.getStringArray("names");
lastFmDescriptions = extras.getStringArray("descriptions");

updateLastFmCards();
}
};


And here is my MainActivity:



ColorsFragment colorsFragment;
LyricsFragment lyricsFragment;
LastFmFragment lastFmFragment;

BottomNavigationView bottomNavigationView;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);

if (!isNotificationServiceRunning()) {
startActivity(new Intent("android.settings.ACTION_NOTIFICATION_LISTENER_SETTINGS"));
}

colorsFragment = new ColorsFragment();
lyricsFragment = new LyricsFragment();
lastFmFragment = new LastFmFragment();

bottomNavigationView = (BottomNavigationView) findViewById(R.id.bottom_navigation);
bottomNavigationView.setOnNavigationItemSelectedListener(menuItem -> {
Fragment fragment = null;

switch (menuItem.getItemId()) {
case R.id.nav_colors:
fragment = colorsFragment;
break;
case R.id.nav_lyrics:
fragment = lyricsFragment;
break;
case R.id.nav_last_fm:
fragment = lastFmFragment;
break;
}

getSupportFragmentManager().beginTransaction().replace(R.id.fragment_container, fragment).commit();

return true;
});

getSupportFragmentManager().beginTransaction().replace(R.id.fragment_container, colorsFragment).commit();
}


I expect the fragments will load the data sent to them even though they are not yet being displayed in MainActivity.










share|improve this question























  • Add the 3 fragments at the same time and then just control its visibility

    – cutiko
    Dec 30 '18 at 18:09














0












0








0








My MainActivity is loading a fragment (there are 3 in total, controlled by a BottomNavigationBar). Each fragment receive data from LocalBroadcastManager, which is sent from an AsyncTask (since it need to do some network tasks), which is initialized from NotificationListenerService (it gets some music information).



Initially I loaded all the views directly into MainActivity, and they worked well, but since they are three different types of information, I decided to separate them into fragments. Now, only the fragment that is being showed get the data. If I switch to another fragment, it doesn't show anything until NotificationListenerService initialize the tasks again (it only happens when music state is changed). And if I return to the fragment that was showing the data, now it doesn't show it too.



Here is the code from one of my fragments (the three ones follow the same estructure):



String lastFmResults;
String lastFmKodes;
String lastFmDescriptions;

LinearLayout lastFmCards;

@Nullable
@Override
public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.fragment_last_fm, container, false);

lastFmCards = (LinearLayout) view.findViewById(R.id.last_fm_cards);

LocalBroadcastManager.getInstance(getContext()).registerReceiver(broadcastReceiverLastFm, new IntentFilter("LastFM"));

return view;
}

private BroadcastReceiver broadcastReceiverLastFm = new BroadcastReceiver() {
@Override
public void onReceive(Context context, Intent intent) {
Bundle extras = intent.getExtras();
lastFmResults = extras.getStringArray("values");
lastFmKodes = extras.getStringArray("names");
lastFmDescriptions = extras.getStringArray("descriptions");

updateLastFmCards();
}
};


And here is my MainActivity:



ColorsFragment colorsFragment;
LyricsFragment lyricsFragment;
LastFmFragment lastFmFragment;

BottomNavigationView bottomNavigationView;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);

if (!isNotificationServiceRunning()) {
startActivity(new Intent("android.settings.ACTION_NOTIFICATION_LISTENER_SETTINGS"));
}

colorsFragment = new ColorsFragment();
lyricsFragment = new LyricsFragment();
lastFmFragment = new LastFmFragment();

bottomNavigationView = (BottomNavigationView) findViewById(R.id.bottom_navigation);
bottomNavigationView.setOnNavigationItemSelectedListener(menuItem -> {
Fragment fragment = null;

switch (menuItem.getItemId()) {
case R.id.nav_colors:
fragment = colorsFragment;
break;
case R.id.nav_lyrics:
fragment = lyricsFragment;
break;
case R.id.nav_last_fm:
fragment = lastFmFragment;
break;
}

getSupportFragmentManager().beginTransaction().replace(R.id.fragment_container, fragment).commit();

return true;
});

getSupportFragmentManager().beginTransaction().replace(R.id.fragment_container, colorsFragment).commit();
}


I expect the fragments will load the data sent to them even though they are not yet being displayed in MainActivity.










share|improve this question














My MainActivity is loading a fragment (there are 3 in total, controlled by a BottomNavigationBar). Each fragment receive data from LocalBroadcastManager, which is sent from an AsyncTask (since it need to do some network tasks), which is initialized from NotificationListenerService (it gets some music information).



Initially I loaded all the views directly into MainActivity, and they worked well, but since they are three different types of information, I decided to separate them into fragments. Now, only the fragment that is being showed get the data. If I switch to another fragment, it doesn't show anything until NotificationListenerService initialize the tasks again (it only happens when music state is changed). And if I return to the fragment that was showing the data, now it doesn't show it too.



Here is the code from one of my fragments (the three ones follow the same estructure):



String lastFmResults;
String lastFmKodes;
String lastFmDescriptions;

LinearLayout lastFmCards;

@Nullable
@Override
public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.fragment_last_fm, container, false);

lastFmCards = (LinearLayout) view.findViewById(R.id.last_fm_cards);

LocalBroadcastManager.getInstance(getContext()).registerReceiver(broadcastReceiverLastFm, new IntentFilter("LastFM"));

return view;
}

private BroadcastReceiver broadcastReceiverLastFm = new BroadcastReceiver() {
@Override
public void onReceive(Context context, Intent intent) {
Bundle extras = intent.getExtras();
lastFmResults = extras.getStringArray("values");
lastFmKodes = extras.getStringArray("names");
lastFmDescriptions = extras.getStringArray("descriptions");

updateLastFmCards();
}
};


And here is my MainActivity:



ColorsFragment colorsFragment;
LyricsFragment lyricsFragment;
LastFmFragment lastFmFragment;

BottomNavigationView bottomNavigationView;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);

if (!isNotificationServiceRunning()) {
startActivity(new Intent("android.settings.ACTION_NOTIFICATION_LISTENER_SETTINGS"));
}

colorsFragment = new ColorsFragment();
lyricsFragment = new LyricsFragment();
lastFmFragment = new LastFmFragment();

bottomNavigationView = (BottomNavigationView) findViewById(R.id.bottom_navigation);
bottomNavigationView.setOnNavigationItemSelectedListener(menuItem -> {
Fragment fragment = null;

switch (menuItem.getItemId()) {
case R.id.nav_colors:
fragment = colorsFragment;
break;
case R.id.nav_lyrics:
fragment = lyricsFragment;
break;
case R.id.nav_last_fm:
fragment = lastFmFragment;
break;
}

getSupportFragmentManager().beginTransaction().replace(R.id.fragment_container, fragment).commit();

return true;
});

getSupportFragmentManager().beginTransaction().replace(R.id.fragment_container, colorsFragment).commit();
}


I expect the fragments will load the data sent to them even though they are not yet being displayed in MainActivity.







java android android-fragments






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Dec 30 '18 at 17:20









Leonardo SalazarLeonardo Salazar

12




12













  • Add the 3 fragments at the same time and then just control its visibility

    – cutiko
    Dec 30 '18 at 18:09



















  • Add the 3 fragments at the same time and then just control its visibility

    – cutiko
    Dec 30 '18 at 18:09

















Add the 3 fragments at the same time and then just control its visibility

– cutiko
Dec 30 '18 at 18:09





Add the 3 fragments at the same time and then just control its visibility

– cutiko
Dec 30 '18 at 18:09












1 Answer
1






active

oldest

votes


















0














I solved it following this guide:
https://medium.com/@oluwabukunmi.aluko/bottom-navigation-view-with-fragments-a074bfd08711



Instead of replace(), it says I have to use show() and hide(). I only had to modify my MainActivity:



final ColorsFragment colorsFragment = new ColorsFragment();
final LyricsFragment lyricsFragment = new LyricsFragment();
final LastFmFragment lastFmFragment = new LastFmFragment();

final FragmentManager fragmentManager = getSupportFragmentManager();
Fragment activeFragment = colorsFragment;

BottomNavigationView bottomNavigationView;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);

if (!isNotificationServiceRunning()) {
startActivity(new Intent("android.settings.ACTION_NOTIFICATION_LISTENER_SETTINGS"));
}

bottomNavigationView = (BottomNavigationView) findViewById(R.id.bottom_navigation);
bottomNavigationView.setOnNavigationItemSelectedListener(menuItem -> {

switch (menuItem.getItemId()) {
case R.id.nav_colors:
fragmentManager.beginTransaction().hide(activeFragment).show(colorsFragment).commit();
activeFragment = colorsFragment;
break;
case R.id.nav_lyrics:
fragmentManager.beginTransaction().hide(activeFragment).show(lyricsFragment).commit();
activeFragment = lyricsFragment;
break;
case R.id.nav_last_fm:
fragmentManager.beginTransaction().hide(activeFragment).show(lastFmFragment).commit();
activeFragment = lastFmFragment;
break;
}

return true;
});

fragmentManager.beginTransaction().add(R.id.fragment_container, lastFmFragment, "2").hide(lastFmFragment).commit();
fragmentManager.beginTransaction().add(R.id.fragment_container, lyricsFragment, "1").hide(lyricsFragment).commit();
fragmentManager.beginTransaction().add(R.id.fragment_container, colorsFragment, "0").commit();
}





share|improve this answer























    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',
    autoActivateHeartbeat: false,
    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%2f53979784%2fhow-to-make-the-fragments-load-data-from-a-service-even-before-they-are-being-di%23new-answer', 'question_page');
    }
    );

    Post as a guest















    Required, but never shown

























    1 Answer
    1






    active

    oldest

    votes








    1 Answer
    1






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    0














    I solved it following this guide:
    https://medium.com/@oluwabukunmi.aluko/bottom-navigation-view-with-fragments-a074bfd08711



    Instead of replace(), it says I have to use show() and hide(). I only had to modify my MainActivity:



    final ColorsFragment colorsFragment = new ColorsFragment();
    final LyricsFragment lyricsFragment = new LyricsFragment();
    final LastFmFragment lastFmFragment = new LastFmFragment();

    final FragmentManager fragmentManager = getSupportFragmentManager();
    Fragment activeFragment = colorsFragment;

    BottomNavigationView bottomNavigationView;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    if (!isNotificationServiceRunning()) {
    startActivity(new Intent("android.settings.ACTION_NOTIFICATION_LISTENER_SETTINGS"));
    }

    bottomNavigationView = (BottomNavigationView) findViewById(R.id.bottom_navigation);
    bottomNavigationView.setOnNavigationItemSelectedListener(menuItem -> {

    switch (menuItem.getItemId()) {
    case R.id.nav_colors:
    fragmentManager.beginTransaction().hide(activeFragment).show(colorsFragment).commit();
    activeFragment = colorsFragment;
    break;
    case R.id.nav_lyrics:
    fragmentManager.beginTransaction().hide(activeFragment).show(lyricsFragment).commit();
    activeFragment = lyricsFragment;
    break;
    case R.id.nav_last_fm:
    fragmentManager.beginTransaction().hide(activeFragment).show(lastFmFragment).commit();
    activeFragment = lastFmFragment;
    break;
    }

    return true;
    });

    fragmentManager.beginTransaction().add(R.id.fragment_container, lastFmFragment, "2").hide(lastFmFragment).commit();
    fragmentManager.beginTransaction().add(R.id.fragment_container, lyricsFragment, "1").hide(lyricsFragment).commit();
    fragmentManager.beginTransaction().add(R.id.fragment_container, colorsFragment, "0").commit();
    }





    share|improve this answer




























      0














      I solved it following this guide:
      https://medium.com/@oluwabukunmi.aluko/bottom-navigation-view-with-fragments-a074bfd08711



      Instead of replace(), it says I have to use show() and hide(). I only had to modify my MainActivity:



      final ColorsFragment colorsFragment = new ColorsFragment();
      final LyricsFragment lyricsFragment = new LyricsFragment();
      final LastFmFragment lastFmFragment = new LastFmFragment();

      final FragmentManager fragmentManager = getSupportFragmentManager();
      Fragment activeFragment = colorsFragment;

      BottomNavigationView bottomNavigationView;

      @Override
      protected void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
      setContentView(R.layout.activity_main);

      if (!isNotificationServiceRunning()) {
      startActivity(new Intent("android.settings.ACTION_NOTIFICATION_LISTENER_SETTINGS"));
      }

      bottomNavigationView = (BottomNavigationView) findViewById(R.id.bottom_navigation);
      bottomNavigationView.setOnNavigationItemSelectedListener(menuItem -> {

      switch (menuItem.getItemId()) {
      case R.id.nav_colors:
      fragmentManager.beginTransaction().hide(activeFragment).show(colorsFragment).commit();
      activeFragment = colorsFragment;
      break;
      case R.id.nav_lyrics:
      fragmentManager.beginTransaction().hide(activeFragment).show(lyricsFragment).commit();
      activeFragment = lyricsFragment;
      break;
      case R.id.nav_last_fm:
      fragmentManager.beginTransaction().hide(activeFragment).show(lastFmFragment).commit();
      activeFragment = lastFmFragment;
      break;
      }

      return true;
      });

      fragmentManager.beginTransaction().add(R.id.fragment_container, lastFmFragment, "2").hide(lastFmFragment).commit();
      fragmentManager.beginTransaction().add(R.id.fragment_container, lyricsFragment, "1").hide(lyricsFragment).commit();
      fragmentManager.beginTransaction().add(R.id.fragment_container, colorsFragment, "0").commit();
      }





      share|improve this answer


























        0












        0








        0







        I solved it following this guide:
        https://medium.com/@oluwabukunmi.aluko/bottom-navigation-view-with-fragments-a074bfd08711



        Instead of replace(), it says I have to use show() and hide(). I only had to modify my MainActivity:



        final ColorsFragment colorsFragment = new ColorsFragment();
        final LyricsFragment lyricsFragment = new LyricsFragment();
        final LastFmFragment lastFmFragment = new LastFmFragment();

        final FragmentManager fragmentManager = getSupportFragmentManager();
        Fragment activeFragment = colorsFragment;

        BottomNavigationView bottomNavigationView;

        @Override
        protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        if (!isNotificationServiceRunning()) {
        startActivity(new Intent("android.settings.ACTION_NOTIFICATION_LISTENER_SETTINGS"));
        }

        bottomNavigationView = (BottomNavigationView) findViewById(R.id.bottom_navigation);
        bottomNavigationView.setOnNavigationItemSelectedListener(menuItem -> {

        switch (menuItem.getItemId()) {
        case R.id.nav_colors:
        fragmentManager.beginTransaction().hide(activeFragment).show(colorsFragment).commit();
        activeFragment = colorsFragment;
        break;
        case R.id.nav_lyrics:
        fragmentManager.beginTransaction().hide(activeFragment).show(lyricsFragment).commit();
        activeFragment = lyricsFragment;
        break;
        case R.id.nav_last_fm:
        fragmentManager.beginTransaction().hide(activeFragment).show(lastFmFragment).commit();
        activeFragment = lastFmFragment;
        break;
        }

        return true;
        });

        fragmentManager.beginTransaction().add(R.id.fragment_container, lastFmFragment, "2").hide(lastFmFragment).commit();
        fragmentManager.beginTransaction().add(R.id.fragment_container, lyricsFragment, "1").hide(lyricsFragment).commit();
        fragmentManager.beginTransaction().add(R.id.fragment_container, colorsFragment, "0").commit();
        }





        share|improve this answer













        I solved it following this guide:
        https://medium.com/@oluwabukunmi.aluko/bottom-navigation-view-with-fragments-a074bfd08711



        Instead of replace(), it says I have to use show() and hide(). I only had to modify my MainActivity:



        final ColorsFragment colorsFragment = new ColorsFragment();
        final LyricsFragment lyricsFragment = new LyricsFragment();
        final LastFmFragment lastFmFragment = new LastFmFragment();

        final FragmentManager fragmentManager = getSupportFragmentManager();
        Fragment activeFragment = colorsFragment;

        BottomNavigationView bottomNavigationView;

        @Override
        protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        if (!isNotificationServiceRunning()) {
        startActivity(new Intent("android.settings.ACTION_NOTIFICATION_LISTENER_SETTINGS"));
        }

        bottomNavigationView = (BottomNavigationView) findViewById(R.id.bottom_navigation);
        bottomNavigationView.setOnNavigationItemSelectedListener(menuItem -> {

        switch (menuItem.getItemId()) {
        case R.id.nav_colors:
        fragmentManager.beginTransaction().hide(activeFragment).show(colorsFragment).commit();
        activeFragment = colorsFragment;
        break;
        case R.id.nav_lyrics:
        fragmentManager.beginTransaction().hide(activeFragment).show(lyricsFragment).commit();
        activeFragment = lyricsFragment;
        break;
        case R.id.nav_last_fm:
        fragmentManager.beginTransaction().hide(activeFragment).show(lastFmFragment).commit();
        activeFragment = lastFmFragment;
        break;
        }

        return true;
        });

        fragmentManager.beginTransaction().add(R.id.fragment_container, lastFmFragment, "2").hide(lastFmFragment).commit();
        fragmentManager.beginTransaction().add(R.id.fragment_container, lyricsFragment, "1").hide(lyricsFragment).commit();
        fragmentManager.beginTransaction().add(R.id.fragment_container, colorsFragment, "0").commit();
        }






        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Dec 30 '18 at 19:22









        Leonardo SalazarLeonardo Salazar

        12




        12






























            draft saved

            draft discarded




















































            Thanks for contributing an answer to Stack Overflow!


            • Please be sure to answer the question. Provide details and share your research!

            But avoid



            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.


            To learn more, see our tips on writing great answers.




            draft saved


            draft discarded














            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53979784%2fhow-to-make-the-fragments-load-data-from-a-service-even-before-they-are-being-di%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

            Monofisismo

            Angular Downloading a file using contenturl with Basic Authentication

            Olmecas