Program call system crash after taking a photo and returning

Source: Internet
Author: User

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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.