So why does this happen? To find out, we will need to take a close look at the fragment lifecycle. We would like to avoid reloading data from the server when the fragment is restored from the backstack because that creates additional traffic on the webserver, and causes a 1-2 second delay in the UI while the data is loaded. The countries fragment reloads the data from the server instead of using the saved instance state data.We press the back button to move the countries fragment from the backstack to the foreground.Another fragment moves to the foreground and the countries fragment is added to the backstack.While testing this code, we note that something is not quite right with instance state restore in the following scenario: Public void onSaveInstanceState(Bundle outState) Populate countries by extracting them from saved instance state bundle Populate countries by calling AsyncTask View view = inflater.inflate(R.agment_countries, container, false) If I click on fragment B twice, all instances will be added to the back stack and pressing back button will be passed through the two created instances.Private List View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) I think there's something wrong with my code because I want to prevent from adding multiple times a fragment into the back stack. I have some fragments which will be replaced by following method.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |