1

I am new to android. I am trying to develop an app using android fragments. Initially it works nicely.Once i close and reopen the app means fragment not loaded. If anyone knows please let me.

i tried following code

FragmentManager fm = getFragmentManager();
    FragmentTransaction ft = fm.beginTransaction();
    MapFragment llf = new MapFragment();
    ft.replace(R.id.id_new_map, llf);
    ft.commit();

but not working.

sankar ganesh
  • 133
  • 1
  • 8

1 Answers1

1

As Mimmo is directing ... you probably will want to move the code to onResume().

Also, you should use the Fragment Manager, something like below.

FragmentManager fragmentManager = getSupportFragmentManager();
FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction();
fragmentTransaction.add(R.id.list_alphabet_layout, new MapFragment(), getResources(R.id.id_new_map));
fragmentTransaction.commit();
boolean wereThereWereAnyPendingTransactions = fragmentManager.executePendingTransactions();
Al Lelopath
  • 6,448
  • 13
  • 82
  • 139
  • I should add that you should familiarize yourself with the lifecycle by using the diagram show on this question: http://stackoverflow.com/questions/8515936/android-activity-life-cycle-what-are-all-these-methods-for – Al Lelopath Aug 03 '15 at 13:45