How does an Intent deliver large files

What is this question about

The intent is limited in how much data it can deliver

Subdivided down the knowledge point

  1. This section explains why big data cannot be transmitted
  2. What if the business requires big data to be delivered

How to answer

  1. When conveying information before an Activity or component, the intent is usually used to bundle the value. However, it is important not to use the bundle to transmit large amounts of data. Due to the large amount of data transferred, the program ANR, or even directly reported an exception. This is because bundles cannot transfer large amounts of data. Inetent, bundles, etc., use a buffer to transfer data. The maximum buffer is 1MB. So the android occurs when a large amount of data. The OS. TransactionTooLargeException.

  2. But there are usually two solutions.

    Method 1: Write the data to be transferred in a temporary file or database, and then read the data when jumping to another component. This processing method will lead to low efficiency of program operation due to time-consuming reading and writing files.

    Method 2: will need to pass information about data encapsulation of a static class (note that the current component and to jump to the component must belong to the same process, because the process to share data between), in the current components for class content, and then jump to the component to get, this way of processing efficiency is very high, but will damage the independence of the program.

    Depending on the specific situation, the second approach is generally recommended because it greatly improves the efficiency of the program.


How are values passed between Fragments and activities

What is this question about

Examine the problem of multi-page data delivery in normal development

Subdivided down the knowledge point

  1. The relationship between activities and Fragments
  2. How to gracefully transfer values

How to answer

  1. Fragments exist as a subinterface of activities. After the Fragment is tied to the Activity, the Fragment can be used to retrieve the Activity object directly through the getActivity () method, so that the Activity method can be called.

  2. You can get a Fragment instance in an Activity by using the following method:

    FragmentManager fragmentManager = getFragmentManager();

    Fragment fragment = fragmentManager.findFragmentByTag(tag);

    Fragment fragment = fragmentManager.findFragmentById(id);

    Once you get the Fragment, you can call the Fragment method. Also realized the communication function.

So they can get each other’s references, they can get each other’s attributes.


Describe the Fragment lifecycle

What is this question about

Look at the basics of Android, but it’s not enough to just talk about the basics

Subdivided down the knowledge point

  1. The process of life cycle on the official website
  2. Features not reflected in the official website diagram

How to answer

Understanding the Fragment lifecycle is not limited to the diagrams on the official website, but must be based on your own experience.

The fragment is created using onAttach, onCreate, onCreateView, and onActivityCreated methods. Fragment methods include onStart and onResume when visible to the user. Fragment Enters background mode and executes onPause and onStop methods. Fragment is destroyed (or the activity holding it is destroyed), experiencing methods including onPause, onStop, onDestroyView, onDestroy, and onDetach; The onCreate, onCreateView, and onActivityCreated methods can be used to store a fragment object.

  • OnAttach: called when a Fragment is associated with an Activity

  • OnCreate: Initialize the Fragment if you want to retain the basic components of the Fragment after it has paused or stopped and then resumed.

  • OnCreateView: called when the page is drawn for the first time. The View can be created here or null can be returned.

  • OnActivityCreated: Fragment binding to an Activity. After the onCreate method has been executed and returned, UI actions can be performed in this method to interact with the Activity, but not before.

  • OnStart: The Fragment is called back when it is started. The Fragment is visible but not displayed in the foreground, so it cannot interact with users

  • OnResume: Fragment is visible in the foreground and is active. Users can interact with it

  • OnPause: Fragment is in the paused state but is still visible and cannot be interact with

  • OnStop: Stops the Fragment callback. The Fragment is not visible at all

  • OnDestoryView: Destroys views associated with the Fragment, but does not unbind the Activity

  • OnDestory: this method is called when the Fragment is destroyed, usually when the Back key is pressed to exit or when the Fragment is reclaimed, followed by onDetach

  • OnDetach: Corresponding to onAttach, called when the Fragment association with the Activity is cancelled

  • SetUserVisibleHint: Call this method to set whether the Fragment is visible or invisible. You can call getUserVisibleHint() to get the visible or invisible state of your Fragment, or lazy-load it if it is visible