| Normal | setRetainInstance(true) | Description |
|---|---|---|
| onAttach | onAttach | Called once the fragment is associated with its activity. |
| onCreate | - | Called to do initial creation of the fragment. |
| onCreateView | onCreateView | Creates and returns the view hierarchy associated with the fragment. |
| onActivityCreated | onActivityCreated | Tells the fragment that its activity has completed its own Activity.onCreate(). |
| onViewStateRestored | onViewStateRestored | Tells the fragment that all of the saved state of its view hierarchy has been restored. |
| onStart | onStart | Makes the fragment visible to the user (based on its containing activity being started). |
| onResume | onResume | Makes the fragment begin interacting with the user (based on its containing activity being resumed). As a fragment is no longer being used, it goes through a reverse series of callbacks: |
| onPause | onPause | Fragment is no longer interacting with the user either because its activity is being paused or a fragment operation is modifying it in the activity. |
| onSaveInstance | onSaveInstance | Called to ask the fragment to save its current dynamic state, so it can later be reconstructed in a new instance of its process is restarted. |
| onStop | onStop | Fragment is no longer visible to the user either because its activity is being stopped or a fragment operation is modifying it in the activity. |
| onDestroyView | onDestroyView | Allows the fragment to clean up resources associated with its View. |
| onDestroy | - | Called to do final cleanup of the fragment's state. |
| onDetach | onDetach | Called immediately prior to the fragment no longer being associated with its activity. |
In Android, test is not as easy as any other platform. Because Android test cannot be run without emulator. Particulary when it comes to AsyncTask or Service, it is difficult to test because they are different type of thread and hard to check their result. Then, how can we ensure the result of AsyncTask valid? AsyncTask is a thread and an asynchnorous as the name means. So, we need to wait for it finishes its job and need to capture the event. Then, when it happens in AsyncTask. It can be one of onBackground() and onPostExecute() methods. It doesn't matter you use onBackground() or onPostExecute() but I prefer onPostExecute(). Anyway, we can test an AsyncTask if we can hook it. Then, how can we hook it? For that, we can use callback pattern. But we need to delay main thread to wait for the AsyncTask's job done because we want to check the result. So the structure for the test would be like: 1. Create AsyncTask A 2. Injection a callback into A 3. Wait until A finish 4....
Comments
Post a Comment