I'm looking for a way to have my Fragment "resume" it's previous State before I turned my device off (since I had images saved into it). I see whats causing the error but can't find a solution (similar questions didn't seem to be answered on how to go about the OnCreate when you first open the App/Fragment is loaded). When I open my app, it creates the new Fragment on my Main Activity:
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
FragmentTransaction ft = getSupportFragmentManager().beginTransaction();
ft.replace(R.id.container, new HomeFragment(),"Home_Fragment")
.addToBackStack("Home_Fragment").commit();
FragmentTransaction bin = getSupportFragmentManager().beginTransaction();
bin.replace(R.id.my_image_container, new MyImageFragment(), "banner").commit();
// Listening for image to be sent over
RepeatTask();
}
Now I've managed to have my Fragment save all data when I'm switching between fragments, as seen in my Fragment java file below:
HomeFragment hm = (HomeFragment)myContext.getSupportFragmentManager().findFragmentByTag("Home_Fragment");
FragmentTransaction ft = myContext.getSupportFragmentManager().beginTransaction();
ft.replace(R.id.container, hm, "Home_Fragment").commit();
But when I leave the app, meaning I either stop it permanently or turn my phone off and turn it back on, all the data (images) are gone, which makes sense since my Main Activity re-starts it. Do any of you know how I can have my MainActivity not start a new Fragment everytime I open the app but "resume" the old state where I have images saved that I got from my computer via TCP