---
title: "when app is restored the fragment is visible only for a second?"  
description: "when app is restored the fragment is visible only for a second?"  
author: "Anonymous User"  
published: 2014-11-16  
updated: 2014-11-17  
canonical: https://www.mindstick.com/forum/12602/when-app-is-restored-the-fragment-is-visible-only-for-a-second  
category: "android"  
tags: ["android"]  
reading_time: 2 minutes  

---

# when app is restored the fragment is visible only for a second?

I have an app that uses fragments. If I enable "dont keep [activities](https://www.mindstick.com/interview/2589/describe-android-activities-in-brief)", then enter the activity and enter the [fragment](https://www.mindstick.com/forum/12894/how-to-force-recreation-of-activity-fragment-on-restore), then minimize with the [Home](https://www.mindstick.com/articles/126322/how-to-keep-your-home-safe-while-traveling) [button](https://www.mindstick.com/articles/63/how-to-add-button-in-datagridview-in-csharp-dot-net) and reopen the app the following [behavior](https://www.mindstick.com/forum/159354/runtimeexception-and-exception-behavior) occurs - the app restores on the open fragment for about half a [second](https://answers.mindstick.com/qa/41761/how-did-the-second-industrial-revolution-influence-women-s-roles-in-society), and immediately after that the fragment closes and the main activity for the [application](https://www.mindstick.com/articles/12824/calculator-application-in-android) shows.

Do I need to perform some sort of [restore](https://yourviews.mindstick.com/story/1480/ways-to-restore-ecosystems-and-heal-the-planet) state for the fragment [manager](https://www.mindstick.com/articles/13000/perks-of-implementing-a-quotation-manager) for cases like this? Also, why is the fragment showing at all for half a second and then closing?

code for the MainActivity:

myFragment = (MyFragment) MyFragment.create(id);

getSupportFragmentManager().beginTransaction().setCustomAnimations(R.anim.slide_in_right, R.anim.slide_out_left, R.anim.slide_in_left, R.anim.slide_out_right)

//.hide(getMainFragment())

.add(R.id.content, MyFragment.create(id), MY_FRAGMENT_TAG)

.addToBackStack([null](https://www.mindstick.com/forum/33922/how-to-use-null-coalescing-operator-in-c-sharp))

.commit();

setDrawerIndicatorEnabled(false);

## Replies

### Reply by Anonymous User

fragment lifecycle behaves differently when you have used "dont keep activities" enabled.

Normal flow of activity with fragment

MainActivity onCreate

Fragment onAttach

Fragment onCreate

Fragment onCreateView

Fragment onViewCreated

Fragment onActivityCreated

MainActivity onStart

Fragment onStart

But when you have enabled "dont keep activities" and pressed home button then the lifecycle behaves differently as

Fragment onAttach

Fragment onCreate

MainActivity onCreate

Fragment onCreateView

Fragment onViewCreated

Fragment onActivityCreated

MainActivity onStart

Fragment onStart

So, purely depends upon the logic you have written.


---

Original Source: https://www.mindstick.com/forum/12602/when-app-is-restored-the-fragment-is-visible-only-for-a-second

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
