Android MIUI system call does not return the current activity how to resolve

Source: Internet
Author: User

What you've been doing with Android is the WYSIWYG editor, the idea is to use the built-in browser WebView HTML5 attribute contenteditable to implement, such as:
<div id= ' con ' class= ' con ' contenteditable= ' true ' > Please enter Content </div>.

In the actual application process, because needs to insert the picture, therefore must support uses the camera to take pictures and selects the picture from the photo Gallery the function. There is no problem from the chart Gallery, but when you take a picture, there are bugs in the MIUI system of millet that don't appear on other models.

Let's look at the code first, write the code that calls camera:

Camera_picname= "Camera.jpg"; Photo Name
Intent Intent = new Intent (mediastore.action_image_capture);
Intent.setaction (mediastore.action_image_capture);
Intent.putextra (Mediastore.extra_output, Uri.fromfile) (New File (environment.getexternalstoragedirectory () + DefaultDir, Camera_picname));
Startactivityforresult (Intent, 10);

Note that here we use the Startactivityforresult to indicate that the results need to be returned.

You then need to rewrite the Onactivityresult method of the current activity:

@Override
protected void Onactivityresult (int requestcode, int resultcode, Intent data) {
Super.onactivityresult (Requestcode, ResultCode, data);
if (Requestcode = && ResultCode = = ACTIVITY.RESULT_OK) {/* Photo/*
String Imgpath = new File (Environment.getexternalstoragedirectory () +defaultdir, Camera_picname). GetAbsolutePath ();
try {
Thread.Sleep (500); Delay millisecond wait webview.loadurl asynchronous execution complete
catch (Interruptedexception e) {
E.printstacktrace ();
}
Mwebview.loadurl ("Javascript:window.appendcon (' +imgpath+ ');");
}
}

In addition, to prevent the current activity being killed by the system when the camera is called (for example, when there is not enough memory, the system automatically destroys an activity that is not visible in OnPause or OnStop state), we need to overwrite the Onsaveinstancestate method, Saves the state variable value of the current activity.

/* Save the interface state, if the activity accidentally by the system killed, return can restore the status value * *
@Override
public void Onsaveinstancestate (Bundle savedinstancestate) {
Savedinstancestate.putstring ("Msg_con", Htmlsource);
Savedinstancestate.putstring ("Msg_camera_picname", camera_picname);
Super.onsaveinstancestate (savedinstancestate); Implement the parent class method to prevent the current activity from being returned after the last
}

Then, in the OnCreate (Bundle savedinstancestate) method, determine if savedinstancestate is NULL, NOT NULL, and read the last saved temporary variable value.

The entire process in the simulator and other models of the Android device is not a problem, but the red rice phone has a problem! The mobile phone model for this problem is the red-m 1S telecoms version, the MIUI version is: miui-jhccnbf37.0, the integrated Android version is 4.3 jls36c, which is not happening in the simulator or on other phones.

Specific questions:

Click on the photo button, jump to the camera interface, because the camera program is more consumption of system resources, generally this time, most of the system will call the Onsaveinstancestate method to let the app save the interface state value.

Millet MIUI System Most of the time is also normal call onsaveinstancestate method, when the system calls this method, the entire photo process, including after the camera returned to the call to take photos of the activity, are normal.

However, sometimes the millet phone does not call the Onsaveinstancestate method, this time, after taking a photo directly out of the call of his activity (the activity has overridden the Onactivityresult method), will not perform Onactivityresult method. The program does not have any other exceptions.

Floating speculation is: because the red rice miui depth customized Android system, and red rice is the entire millet department of the lowest end of the entry-level, in the hardware performance reduction serious. Vernacular is the modification of too many modules without taking into account the resulting bugs. When the system calls the camera program, the system thinks the current memory is sufficient and the activity is not destroyed, so the Onsaveinstancestate method is not executed. But after the camera is really enabled, the system found that the memory is not enough, will be oom, destroyed in OnPause or onstop activity. This destruction system will not inform you that the system has secretly done this thing.

Normally, even if the system destroys the activity, the system regenerates the destroyed activity, onCreate, etc. when the camera returns to the activity.

However, the MIUI system of Millet has bug! here. Millet MIUI that an activity will not be destroyed, so directly ignores the possibility that the system needs to recreate the activity because of an accident. This leads directly to the return to the former activity rather than the former activity.

When the millet MIUI system explicitly believes that this activity may be destroyed, when the Onsaveinstancestate method is executed, the above bug does not exist, the system can normally return to the previous activity after the photo is completed and execute the Onactivityresult method.

Currently, this bug is not fixed. Above is floating easy personal humble opinion, welcome expert comment.

Incidentally, another bug in the red meter phone:

One, sometimes in the mobile phone browser to visit the Web page or return, the entire page does not show complete, the page part of the elements show incomplete, fault, you must manually refresh the current page to display all the pages.

Second, when you open the app, click the button to return, for example, when the camera returned, some of the controls on the interface are black, must be the fingers sliding over these controls to remove black.

Do not know other small partners, have not encountered as a bug.

Related Article

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: info-contact@alibabacloud.com 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.