Call getActivity () in Fragment to report null. activity calls fragment.
Check umeng's error log and find that NullPointerException occurs again. Then, check the code and find that only the context is available, however, this situation has already occurred before, so I uploaded the context from the Activity when I created the Fragment object. I tested it multiple times and there is no problem, after finding information on the Internet, I found many cases where getActivity () is empty. I found that I ignored the following problem: If the app runs in the background for a long time, crash may occur when you enter the app again. The Activity may be recycled by the system and rebuilt. However, Fragment will not be recycled as the Activity is recycled, and the created Fragment will be saved to the Bundle, this causes Fragment to lose the Activity.
To solve this problem, I think of a solution: when the Activity is destroyed, the bound Fragmetn is destroyed at the same time, the onSaveInstanceState method is rewritten in the Activity, and super is commented out. onSaveInstanceState (outState), so that the Activity does not save the Fragment status.