Recently, I used the system to take photos to get photos. When I used it on Samsung's mobile phone, I found that ondestroy () was called to call the life cycle of the activity that triggered the response when the camera took the photos () --> oncreate (); repeat the oncreate () method, leading to system crash.
Method 1: At the beginning, the onsaveinstancestate (bundle savedinstancestate) and onrestoreinstancestate (bundle savedinstancestate) methods were called for implementation. Although the method is stupid, however, you can save some of the variables you need in onsaveinstancestate and determine whether savedinstancestate is null in the oncreate () method. If it is not null, onrestoreinstancestate () is called () the method is used to retrieve the previously stored variables, which is equivalent to reloading the current activity on one side.
Method 2: the above method is feasible, but it is not the fundamental solution to the problem. Later, we found that when calling the camera, the activity switched from the portrait screen to the landscape screen, after you find the root cause of the activity, you can use Android: configchanges = "orientation | keyboardhidden" in the activity"
This attribute can restrict the status of the portrait screen of the current activity to remain unchanged when calling the camera, thus solving the problem of activity reloading.