CN106155741B - It is a kind of to avoid processing unit and method of the application program without response - Google Patents

It is a kind of to avoid processing unit and method of the application program without response Download PDF

Info

Publication number
CN106155741B
CN106155741B CN201610510502.8A CN201610510502A CN106155741B CN 106155741 B CN106155741 B CN 106155741B CN 201610510502 A CN201610510502 A CN 201610510502A CN 106155741 B CN106155741 B CN 106155741B
Authority
CN
China
Prior art keywords
module
incoming event
main thread
response
thread
Prior art date
Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
Active
Application number
CN201610510502.8A
Other languages
Chinese (zh)
Other versions
CN106155741A (en
Inventor
安占磊
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
Nubia Technology Co Ltd
Original Assignee
Nubia Technology Co Ltd
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by Nubia Technology Co Ltd filed Critical Nubia Technology Co Ltd
Priority to CN201610510502.8A priority Critical patent/CN106155741B/en
Publication of CN106155741A publication Critical patent/CN106155741A/en
Application granted granted Critical
Publication of CN106155741B publication Critical patent/CN106155741B/en
Active legal-status Critical Current
Anticipated expiration legal-status Critical

Links

Classifications

    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F9/00Arrangements for program control, e.g. control units
    • G06F9/06Arrangements for program control, e.g. control units using stored programs, i.e. using an internal store of processing equipment to receive or retain programs
    • G06F9/44Arrangements for executing specific programs
    • G06F9/445Program loading or initiating
    • G06F9/44505Configuring for program initiating, e.g. using registry, configuration files

Landscapes

  • Engineering & Computer Science (AREA)
  • Software Systems (AREA)
  • Theoretical Computer Science (AREA)
  • Physics & Mathematics (AREA)
  • General Engineering & Computer Science (AREA)
  • General Physics & Mathematics (AREA)
  • Telephone Function (AREA)
  • Mobile Radio Communication Systems (AREA)

Abstract

Processing unit and method of the application program without response are avoided the invention discloses a kind of.Wherein, which includes first detection module, for sending and notifying to interrupt module when detecting main thread to incoming event without response;Interrupt module, for generating interrupt signal after receiving the notice of detection module;Proxy module, the treatment progress for after detecting the interrupt signal of interrupt module, terminating and saving main thread to incoming event, and promoter threading models;Sub thread module, for handling the subsequent processes of incoming event.The present invention improves system to the execution efficiency of incoming event, is effectively improved the usage experience of user it is possible to prevente effectively from the ANR message that main thread is generated by response timeout.

Description

It is a kind of to avoid processing unit and method of the application program without response
Technical field
The present invention relates to field electronic technology field more particularly to a kind of processing unit for avoiding application program without response and Method.
Background technique
Widely available with intelligent terminal, it is more and more perfect to install the function that application program at the terminal is realized, Correspondingly, the structure of these application programs itself also becomes increasingly complex, therefore behaves and also more expend system resource.Mesh Before, Android operation system is generallyd use in mobile terminal as operating platform.However in Android platform, if mobile Application program responds not sensitive enough for some time in terminal, and system can show a prompting application program without response to user Dialog box, this dialog box are known as application program without response (ANR:Application Not Responding) dialog box, use Family, which can choose waiting, allows application program to continue to run, and also can choose " positive closing ".
Due to Android application program be usually operate in an individual thread such as main thread, if using Operation performed by program occupies the too many resource of main thread, main thread just have no ability to reprocessing user I/O operation or Intent broadcast is received, application program does not respond yet after predetermined period of time, and system will default the application program Through hanging up, at this moment terminal will usually show that an ANR dialog box is supplied to user, by user selection terminate the application program or Continue waiting for system response.In APP operation, ANR occur is to allow very much people irritated, brings excessively poor user experience. So to avoid generating ANR as far as possible when designing Android application program.
Summary of the invention
It is a primary object of the present invention to propose a kind of processing unit and method for avoiding application program without response, it is intended to solve The problem of application program is without response ANR is certainly easy to happen in Android operation system in the prior art.
It is to achieve the above object, provided by the invention a kind of to avoid processing unit of the application program without response, comprising:
First detection module, for sending and notifying to interrupt module when detecting main thread to incoming event without response;
The interrupt module, for generating interrupt signal after receiving the notice of the detection module;
Proxy module saves the main thread to institute for terminating after the interrupt signal for detecting the interrupt module State the treatment progress of incoming event, and promoter threading models;
The sub thread module, for handling the subsequent processes of the incoming event.
Further, the first detection module is specifically used for:
Detect whether main thread responds incoming event in the first preset time;Wherein, described first it is default when Between be less than 200ms.
Further, the sub thread module is also used to after the completion of incoming event processing, Xiang Suoshu proxy module Send message;
The proxy module after being also used to receive the message, notifies the main thread more new user interface.
Further, described device further includes judgment module, for judging whether the incoming event is handled by main thread;
If the incoming event is handled by main thread, notify that the first detection module is detected.
Further, the judgment module is also used to, if the incoming event notifies the second inspection by non-master thread process Module is surveyed to be detected;
Second detection module, for detecting whether the incoming event has response within the second response time;
Cue module, for generating application program and being mentioned without response ANR when second detection module detection is without response Show.
In addition, to achieve the above object, the present invention also proposes a kind of processing method for avoiding application program without response, packet It includes:
When detecting main thread to incoming event without response, interrupt signal is generated;
If terminating after main thread agency detects the interrupt signal and saving the main thread to the incoming event Treatment progress, and promoter thread process subsequent processes.
Further, detect whether main thread responds incoming event in the first preset time;Wherein, described One preset time is less than 200ms.
Further, the method also includes:
After the incoming event is completed in sub thread processing, is acted on behalf of to main thread and send message;
After the main thread agency receives message, the main thread more new user interface is notified.
Further, the method also includes:
Judge whether the incoming event is handled by main thread;
If the incoming event is handled by main thread, the main thread is detected in the first preset time to incoming event Whether there is or not responses.
Further, the method also includes:
If the incoming event detects whether the incoming event has by non-master thread process within the second response time Response;
When detection is without response, generates application program and prompted without response.It is avoided provided by the embodiment of the present invention using journey Processing unit of the sequence without response realizes main thread for the response timeout of incoming event by configuring individual first detection module Detection;After detecting the interrupt signal that interrupt module is generated by time-out detection, terminated by agentbased control main thread;Proxy module The processing progress of incoming event is saved, and controls the subsequent processes of sub thread processing incoming event.It therefore, through the invention can be with The ANR message for effectively main thread being avoided to generate by response timeout;Simultaneously by sub thread processing subsequent processes, effectively improves and be The execution efficiency united to incoming event, is effectively improved the usage experience of user.
Detailed description of the invention
The hardware structural diagram of Fig. 1 optional mobile terminal of each embodiment one to realize the present invention;
Fig. 2 is the wireless communication system schematic diagram of mobile terminal as shown in Figure 1;
Fig. 3 is that the present invention avoids application program without the structural schematic diagram of the processing unit of response;
Fig. 4 is that the present invention avoids application program without the flow chart of the processing method of response;
Fig. 5 is that the present invention avoids application program without the flow chart of the specific embodiment of the processing method of response.
The embodiments will be further described with reference to the accompanying drawings for the realization, the function and the advantages of the object of the present invention.
Specific embodiment
It should be appreciated that the specific embodiments described herein are merely illustrative of the present invention, it is not intended to limit the present invention.
The mobile terminal of each embodiment of the present invention is realized in description with reference to the drawings.In subsequent description, use For indicate element such as " module ", " component " or " unit " suffix only for being conducive to explanation of the invention, itself There is no specific meanings.Therefore, " module " can be used mixedly with " component ".
Mobile terminal can be implemented in a variety of manners.For example, terminal described in the present invention may include such as moving Phone, smart phone, laptop, digit broadcasting receiver, PDA (personal digital assistant), PAD (tablet computer), PMP The mobile terminal of (portable media player), navigation device etc. and such as number TV, desktop computer etc. are consolidated Determine terminal.Hereinafter it is assumed that terminal is mobile terminal.However, it will be understood by those skilled in the art that in addition to being used in particular for moving Except the element of purpose, the construction of embodiment according to the present invention can also apply to the terminal of fixed type.
The hardware structural diagram of Fig. 1 optional mobile terminal of each embodiment one to realize the present invention.
Mobile terminal 100 may include user input unit 130, output unit 150, memory 160, interface unit 170, Controller 180 and power supply unit 190 etc..Fig. 1 shows the mobile terminal with various assemblies, it should be understood that simultaneously All components shown realistic are not applied.More or fewer components can alternatively be implemented.Movement will be discussed in more detail below The element of terminal.
Wireless communication unit 110 generally includes one or more components, allows mobile terminal 100 and wireless communication system Or the radio communication between network.For example, wireless communication unit may include broadcasting reception module 111, mobile communication module 112, at least one of wireless Internet module 113, short range communication module 114 and location information module 115.
Broadcasting reception module 111 receives broadcast singal and/or broadcast from external broadcast management server via broadcast channel Relevant information.Broadcast channel may include satellite channel and/or terrestrial channel.Broadcast management server, which can be, to be generated and sent The broadcast singal and/or broadcast related information generated before the server or reception of broadcast singal and/or broadcast related information And send it to the server of terminal.Broadcast singal may include TV broadcast singal, radio signals, data broadcasting Signal etc..Moreover, broadcast singal may further include the broadcast singal combined with TV or radio signals.Broadcast phase Closing information can also provide via mobile communications network, and in this case, broadcast related information can be by mobile communication mould Block 112 receives.Broadcast singal can exist in a variety of manners, for example, it can be with the electronics of digital multimedia broadcasting (DMB) Program guide (EPG), digital video broadcast-handheld (DVB-H) electronic service guidebooks (ESG) etc. form and exist.Broadcast Receiving module 111 can receive signal broadcast by using various types of broadcast systems.Particularly, broadcasting reception module 111 It can be wide by using such as multimedia broadcasting-ground (DMB-T), digital multimedia broadcasting-satellite (DMB-S), digital video It broadcasts-holds (DVB-H), the Radio Data System of forward link media (MediaFLO@), received terrestrial digital broadcasting integrated service (ISDB-T) etc. digit broadcasting system receives digital broadcasting.Broadcasting reception module 111, which may be constructed such that, to be adapted to provide for extensively Broadcast the various broadcast systems and above-mentioned digit broadcasting system of signal.Via the received broadcast singal of broadcasting reception module 111 and/ Or broadcast related information can store in memory 160 (or other types of storage medium).
Mobile communication module 112 sends radio signals to base station (for example, access point, node B etc.), exterior terminal And at least one of server and/or receive from it radio signal.Such radio signal may include that voice is logical Talk about signal, video calling signal or according to text and/or Multimedia Message transmission and/or received various types of data.
The Wi-Fi (Wireless Internet Access) of the support mobile terminal of wireless Internet module 113.The module can be internally or externally It is couple to terminal.Wi-Fi (Wireless Internet Access) technology involved in the module may include WLAN (Wireless LAN) (Wi-Fi), Wibro (WiMAX), Wimax (worldwide interoperability for microwave accesses), HSDPA (high-speed downlink packet access) etc..
Short range communication module 114 is the module for supporting short range communication.Some examples of short-range communication technology include indigo plant ToothTM, radio frequency identification (RFID), Infrared Data Association (IrDA), ultra wide band (UWB), purple honeybeeTMEtc..
Location information module 115 is the module for checking or obtaining the location information of mobile terminal.Location information module Typical case be GPS (global positioning system).According to current technology, GPS module 115, which calculates, comes from three or more satellites Range information and correct time information and the Information application triangulation for calculating, thus according to longitude, latitude Highly accurately calculate three-dimensional current location information.Currently, it is defended for the method for calculating position and temporal information using three Star and the error that calculated position and temporal information are corrected by using an other satellite.In addition, GPS module 115 It can be by Continuous plus current location information in real time come calculating speed information.
A/V input unit 120 is for receiving audio or video signal.A/V input unit 120 may include 121 He of camera Microphone 122, camera 121 is to the static images obtained in video acquisition mode or image capture mode by image capture apparatus Or the image data of video is handled.Treated, and picture frame may be displayed on display unit 151.It is handled through camera 121 Picture frame afterwards can store in memory 160 (or other storage mediums) or be sent out via wireless communication unit 110 It send, two or more cameras 121 can be provided according to the construction of mobile terminal.Microphone 122 can be in telephone calling model, note Sound (audio data) is received via microphone in record mode, speech recognition mode etc. operational mode, and can will in this way Acoustic processing be audio data.Audio that treated (voice) data can be converted in the case where telephone calling model can The format output of mobile communication base station is sent to via mobile communication module 112.Various types of make an uproar can be implemented in microphone 122 Sound eliminates (or inhibition) algorithm to eliminate the noise or do that (or inhibition) generates during sending and receiving audio signal It disturbs.
The order that user input unit 130 can be inputted according to user generates key input data to control each of mobile terminal Kind operation.User input unit 130 allows user to input various types of information, and may include keyboard, metal dome, touch Plate (for example, the sensitive component of detection due to the variation of resistance, pressure, capacitor etc. caused by being contacted), idler wheel, rocking bar etc. Deng.Particularly, when touch tablet is superimposed upon in the form of layer on display unit 151, touch screen can be formed.
Interface unit 170 be used as at least one external device (ED) connect with mobile terminal 100 can by interface.For example, External device (ED) may include wired or wireless headphone port, external power supply (or battery charger) port, wired or nothing Line data port, memory card port, the port for connecting the device with identification module, audio input/output (I/O) end Mouth, video i/o port, ear port etc..Identification module can be storage and use each of mobile terminal 100 for verifying user It plants information and may include subscriber identification module (UIM), client identification module (SIM), Universal Subscriber identification module (USIM) Etc..In addition, the device (hereinafter referred to as " identification device ") with identification module can take the form of smart card, therefore, know Other device can be connect via port or other attachment devices with mobile terminal 100.Interface unit 170, which can be used for receiving, to be come from The input (for example, data information, electric power etc.) of external device (ED) and the input received is transferred in mobile terminal 100 One or more elements can be used for transmitting data between mobile terminal and external device (ED).
In addition, when mobile terminal 100 is connect with external base, interface unit 170 may be used as allowing will be electric by it Power, which is provided from pedestal to the path or may be used as of mobile terminal 100, allows the various command signals inputted from pedestal to pass through it It is transferred to the path of mobile terminal.The various command signals or electric power inputted from pedestal, which may be used as mobile terminal for identification, is The no signal being accurately fitted on pedestal.Output unit 150 is configured to provide with vision, audio and/or tactile manner defeated Signal (for example, audio signal, vision signal, alarm signal, vibration signal etc.) out.Output unit 150 may include display Unit 151, audio output module 152, alarm unit 153 etc..
Display unit 151 may be displayed on the information handled in mobile terminal 100.For example, when mobile terminal 100 is in electricity When talking about call mode, display unit 151 can show and converse or other communicate (for example, text messaging, multimedia file Downloading etc.) relevant user interface (UI) or graphic user interface (GUI).When mobile terminal 100 is in video calling mode Or when image capture mode, display unit 151 can show captured image and/or received image, show video or figure Picture and the UI or GUI of correlation function etc..
Meanwhile when display unit 151 and touch tablet in the form of layer it is superposed on one another to form touch screen when, display unit 151 may be used as input unit and output device.Display unit 151 may include liquid crystal display (LCD), thin film transistor (TFT) In LCD (TFT-LCD), Organic Light Emitting Diode (OLED) display, flexible display, three-dimensional (3D) display etc. at least It is a kind of.Some in these displays may be constructed such that transparence to allow user to watch from outside, this is properly termed as transparent Display, typical transparent display can be, for example, TOLED (transparent organic light emitting diode) display etc..According to specific Desired embodiment, mobile terminal 100 may include two or more display units (or other display devices), for example, moving Dynamic terminal may include outernal display unit (not shown) and inner display unit (not shown).Touch screen can be used for detecting touch Input pressure and touch input position and touch input area.
Audio output module 152 can mobile terminal be in call signal reception pattern, call mode, logging mode, It is when under the isotypes such as speech recognition mode, broadcast reception mode, wireless communication unit 110 is received or in memory 160 The audio data transducing audio signal of middle storage and to export be sound.Moreover, audio output module 152 can provide and movement The relevant audio output of specific function (for example, call signal receives sound, message sink sound etc.) that terminal 100 executes. Audio output module 152 may include loudspeaker, buzzer etc..
Alarm unit 153 can provide output notifying event to mobile terminal 100.Typical event can be with Including calling reception, message sink, key signals input, touch input etc..Other than audio or video output, alarm unit 153 can provide output in different ways with the generation of notification event.For example, alarm unit 153 can be in the form of vibration Output is provided, when receiving calling, message or some other entrance communications (incomingcommunication), alarm list Member 153 can provide tactile output (that is, vibration) to notify to user.By providing such tactile output, even if When the mobile phone of user is in the pocket of user, user also can recognize that the generation of various events.Alarm unit 153 The output of the generation of notification event can be provided via display unit 151 or audio output module 152.
Memory 160 can store the software program etc. of the processing and control operation that are executed by controller 180, Huo Zheke Temporarily to store oneself data (for example, telephone directory, message, still image, video etc.) through exporting or will export.And And memory 160 can store about the vibrations of various modes and audio signal exported when touching and being applied to touch screen Data.
Memory 160 may include the storage medium of at least one type, and the storage medium includes flash memory, hard disk, more Media card, card-type memory (for example, SD or DX memory etc.), random access storage device (RAM), static random-access storage Device (SRAM), read-only memory (ROM), electrically erasable programmable read-only memory (EEPROM), programmable read only memory (PROM), magnetic storage, disk, CD etc..Moreover, mobile terminal 100 can execute memory with by network connection The network storage device of 160 store function cooperates.
The overall operation of the usually control mobile terminal of controller 180.For example, controller 180 executes and voice communication, data Communication, video calling etc. relevant control and processing.In addition, controller 180 may include for reproducing (or playback) more matchmakers The multi-media module 181 of volume data, multi-media module 181 can construct in controller 180, or can be structured as and control Device 180 separates.Controller 180 can be with execution pattern identifying processing, by the handwriting input executed on the touchscreen or picture It draws input and is identified as character or image.
Power supply unit 190 receives external power or internal power under the control of controller 180 and provides operation each member Electric power appropriate needed for part and component.
Various embodiments described herein can be to use the calculating of such as computer software, hardware or any combination thereof Machine readable medium is implemented.Hardware is implemented, embodiment described herein can be by using application-specific IC (ASIC), digital signal processor (DSP), digital signal processing device (DSPD), programmable logic device (PLD), scene can Programming gate array (FPGA), controller, microcontroller, microprocessor, is designed to execute function described herein processor At least one of electronic unit is implemented, and in some cases, such embodiment can be implemented in controller 180. For software implementation, the embodiment of such as process or function can with allow to execute the individual of at least one functions or operations Software module is implemented.Software code can by the software application (or program) write with any programming language appropriate Lai Implement, software code can store in memory 160 and be executed by controller 180.
So far, oneself is through describing mobile terminal according to its function.In the following, for the sake of brevity, will description such as folded form, Slide type mobile terminal in various types of mobile terminals of board-type, oscillating-type, slide type mobile terminal etc., which is used as, to be shown Example.Therefore, the present invention can be applied to any kind of mobile terminal, and be not limited to slide type mobile terminal.
Mobile terminal 100 as shown in Figure 1 may be constructed such that using via frame or grouping send data it is all if any Line and wireless communication system and satellite-based communication system operate.
Referring now to Fig. 2 description communication system that wherein mobile terminal according to the present invention can operate.
Different air interface and/or physical layer can be used in such communication system.For example, used by communication system Air interface includes such as frequency division multiple access (FDMA), time division multiple acess (TDMA), CDMA (CDMA) and universal mobile communications system System (UMTS) (particularly, long term evolution (LTE)), global system for mobile communications (GSM) etc..As non-limiting example, under The description in face is related to cdma communication system, but such introduction is equally applicable to other types of system.
With reference to Fig. 2, cdma wireless communication system may include multiple mobile terminals 100, multiple base stations (BS) 270, base station Controller (BSC) 275 and mobile switching centre (MSC) 280.MSC280 is configured to and Public Switched Telephony Network (PSTN) 290 form interface.MSC280 is also structured to form interface with the BSC275 that can be couple to base station 270 via back haul link. Back haul link can be constructed according to any in several known interfaces, and the interface includes such as E1/T1, ATM, IP, PPP, frame relay, HDSL, ADSL or xDSL.It will be appreciated that system may include multiple BSC2750 as shown in Figure 2.
Each BS270 can service one or more subregions (or region), by multidirectional antenna or the day of direction specific direction Each subregion of line covering is radially far from BS270.Alternatively, each subregion can be by two or more for diversity reception Antenna covering.Each BS270, which may be constructed such that, supports multiple frequency distribution, and the distribution of each frequency has specific frequency spectrum (for example, 1.25MHz, 5MHz etc.).
What subregion and frequency were distributed, which intersects, can be referred to as CDMA Channel.BS270 can also be referred to as base station transceiver System (BTS) or other equivalent terms.In this case, term " base station " can be used for broadly indicating single BSC275 and at least one BS270.Base station can also be referred to as " cellular station ".Alternatively, each subregion of specific BS270 can be claimed For multiple cellular stations.
As shown in Figure 2, broadcast singal is sent to the mobile terminal operated in system by broadcsting transmitter (BT) 295 100.Broadcasting reception module 111 as shown in Figure 1 is arranged at mobile terminal 100 to receive the broadcast sent by BT295 Signal.In fig. 2 it is shown that several global positioning system (GPS) satellites 300.The help of satellite 300 positions multiple mobile terminals At least one of 100.
In Fig. 2, multiple satellites 300 are depicted, it is understood that, it is useful to can use any number of satellite acquisition Location information.GPS module 115 as shown in Figure 1 is generally configured to cooperate with satellite 300 to obtain desired positioning and believe Breath.It substitutes GPS tracking technique or except GPS tracking technique, the other of the position that can track mobile terminal can be used Technology.In addition, at least one 300 property of can choose of GPS satellite or extraly processing satellite dmb transmission.
As a typical operation of wireless communication system, BS270 receives the reverse link from various mobile terminals 100 Signal.Mobile terminal 100 usually participates in call, information receiving and transmitting and other types of communication.Certain base station 270 is received each anti- It is handled in specific BS270 to link signal.The data of acquisition are forwarded to relevant BSC275.BSC provides call The mobile management function of resource allocation and the coordination including the soft switching process between BS270.The number that BSC275 will also be received According to MSC280 is routed to, the additional route service for forming interface with PSTN290 is provided.Similarly, PSTN290 with MSC280 forms interface, and MSC and BSC275 form interface, and BSC275 controls BS270 correspondingly with by forward link signals It is sent to mobile terminal 100.
Based on above-mentioned mobile terminal hardware configuration and communication system, each embodiment of the method for the present invention is proposed.
Fig. 3 is to avoid application program without the structural schematic diagram of the processing unit of response in the embodiment of the present invention.Device tool Body includes: first detection module 31, interrupt module 32, proxy module 33 and sub thread module 34;Wherein,
First detection module 31, for being sent to interrupt module 32 when detecting main thread to incoming event without response Notice;
Interrupt module 32, for generating interrupt signal after receiving the notice of detection module;
Proxy module 33 after the interrupt signal for detecting interrupt module 32, terminates and saves main thread to incoming event Treatment progress, and promoter threading models;
Sub thread module 34, for handling the subsequent processes of incoming event.
Avoid application program without the processing unit of response provided by the embodiment of the present invention, by configuring individual first inspection It surveys module 31 and realizes that main thread detects the response timeout of incoming event;When detect interrupt module 32 because time-out detection generate Interrupt signal after, terminated by agentbased control main thread;Agency saves the processing progress of incoming event, and controls sub thread processing The subsequent processes of incoming event.Therefore, through the invention it is possible to prevente effectively from the ANR that main thread is generated by response timeout disappears Breath;Subsequent processes are handled by sub thread simultaneously, system is effectively improved to the execution efficiency of incoming event, is effectively improved user's Usage experience.
Specific implementation process of the invention is described in further detail below.
First detection module 31, for being sent to interrupt module 32 when detecting main thread to incoming event without response Notice.
Wherein, since sensation time of the user to interface Caton is 100~200ms, in order to avoid user feels to block , in the embodiment of the present invention, the detection time of first detection module 31 is arranged within 200ms.
Wherein, main thread refers to the user interface main thread of system.The thread android system run when just by Creation, for being responsible for display, update and the widget interaction at the control interface UI.
Wherein, incoming event includes click event, double click event, stroke event etc..In android system, set in advance Event distributor has been set, for incoming event to be distributed in active window, event has specifically been operated by main thread.
Specifically, case distribution device defines incoming event and processing type.When case distribution device receives the defeated of user After incoming event, the processing type of response is called according to incoming event, and the processing type is distributed to movable application widget.
Wherein, the UI of movable application widget, which is updated, is responsible for processing by main thread.Therefore, when receive case distribution device hair After the event type sent, corresponding event handling function is called to be handled according to event type.After to thread process, return Return processing response.If after first detection module 31 can't detect the processing response of main thread in preset detection time, Interrupt module 32 is notified to carry out interrupt processing.
Interrupt module 32, for generating interrupt signal after receiving the notice of detection module.
Wherein, the generation of interrupt signal is done by calling Thread.interrupt () method. Thread.interrupt () method has modified the interruption of main thread by obtaining the detection signal in first detection module 31 State is acted on behalf of to inform.
Specifically, for the main thread in non-obstruction, after the detection of first detection module 31 has response, interrupt module 32 is not done Interrupt processing, i.e. state are non-interrupted state;By calling Thread.isInterrupted () method, interrupt status is returned Return true;
For the main thread in abolishable blocked state, for example, etc. pending time-consuming sub thread, Thread.sleep (), Object.wait (), Thread.join (), after first detection module 31 detects main thread response timeout, interrupt module 32 can dish out InterruptedException, while interrupt status can be put back into as false.
Proxy module 33 after the interrupt signal for detecting interrupt module 32, terminates and saves main thread to incoming event Treatment progress, and promoter threading models 34.
Wherein, proxy module 33 is used to act on behalf of the access process of main thread.Maintenance main thread is responsible for by proxy module 33 State and function.In the embodiment of the present invention, proxy module 33 can be realized by Java dynamic proxy mechanism, due to Java dynamic Agency mechanism already belongs to technology well-known to those skilled in the art.Therefore, the specific implementation no longer to proxy module 33 here It is repeated.
Specifically, when application widget starts, the function that main thread calls all is registered to proxy module 33.In event point Hair device is distributed to main thread processing incoming event, at this moment main thread is to agency when detecting incoming event is main thread process The transmission of module 33 has a proxy requests.Since the function that main thread calls all is registered to proxy module 33, main thread sends generation After reason request, proxy module 33 will be directed toward the specific calling function of the incoming event.
Wherein, for the acquisition of 32 interrupt signal of interrupt module, proxy module 33 can pass through Thread.isInterrupted () reads main thread interrupt status.After proxy module 33 gets interrupt signal, will in Disconnected state puts back into as true, and the interrupt status is avoided to have an impact the processing of other threads.One can specifically be passed through The static method of Thread.interrupted () reads and removes interrupt status value.
Wherein, proxy module 33 detects interrupt signal, terminates main thread in time and continues to handle to incoming event, together Shi Baocun incoming event executes field data.After field data preservation, the reduction of promoter thread process executes scene to not holding The incoming event gone continues to execute.
As can be seen that proxy module 33 acts on behalf of the various operations of main thread, in the embodiment of the present invention convenient for capturing end After end signal, operation is terminated in time, new trigger event is handled convenient for main thread and is handled;It is directed to interrupt operation simultaneously, Behind the execution scene for saving incoming event, sets up another sub thread reduction execution scene and the operation being not carried out is continued to execute.Therefore, It transfers to the sub thread on backstage to continue to handle time-consuming incoming event by proxy module 33, does not influence the interface behaviour of user Make, while promoting the interactive experience of user.
Sub thread module 34, for handling the subsequent processes of incoming event.
Wherein, UI can not directly be updated in usual sub thread.If directly refreshing sub thread, it will usually dish out following different Often.Therefore, after sub thread is disposed, or by the update of main thread completion UI.
Specifically, it after the completion of sub thread module 34 handles the subsequent processes of incoming event, is sent to proxy module 33 logical Know;After proxy module 33 receives notice, notice main thread updates UI.
Handler, can be with various interactions as the interaction channel between sub thread and main thread.In the embodiment of the present invention, Using handler+message mode, UI is updated by sub thread notice main thread.
Specifically, a Handler processor is pre-created in proxy module 33, for monitoring the Message thing of sub thread Part.After group thread process finishes the process of incoming event, state changes, then issues event handling and finish information Message.After Handler processor listens to the Message that incoming event processing is completed, notice main thread updates UI.
Further, in one embodiment of the present of invention, avoid processing unit of the application program without response in addition to including the It further include that judgment module 35, second is examined except one detection module 31, interrupt module 32, proxy module 33 and sub thread module 34 Survey module 36 and cue module 37;Wherein,
Judgment module 35, for judging whether incoming event is handled by main thread:
When determining that incoming event handles by main thread, then notify that first detection module 31 is detected;
When determine incoming event by non-master thread process, then notify that the second detection module 36 is detected.
Second detection module 36, for detecting whether the incoming event has response within the second response time;Wherein Two response times were greater than for the first response time, were set as 5s.
Cue module 37, for generating application program and being mentioned without response ANR when the detection of the second detection module 36 is without response Show.
As can be seen that avoid application program that the processing unit of ANR occurs in the present embodiment, it is main to realize application program master Thread there is a situation where ANR, for the triggering of non-main thread ANR the case where, that is, ANR does not do and locates caused by system trigger Reason, enables the treatment mechanism of system itself effectively to avoid the ANR of main thread while not being destroyed.
Fig. 4 is to avoid application program without the flow chart of the processing method of response in the embodiment of the present invention.This method is specific to wrap Include following steps:
Step 401, when detect main thread to incoming event without response when, generate interrupt signal;
Step 402, if after detecting interrupt signal, the treatment progress for terminating and saving main thread to incoming event, to open Mover thread process subsequent processes.
Avoid application program without the processing method of response provided by the embodiment of the present invention, by configuring individually detection mould Block realizes that main thread detects the response timeout of incoming event;After detecting the interrupt signal that time-out detection generates, by leading Thread agentbased control main thread terminates;Main thread agency saves the processing progress of incoming event, and controls sub thread processing input The subsequent processes of event.Therefore, through the invention it is possible to prevente effectively from the ANR message that main thread is generated by response timeout;Together When by sub thread handle subsequent processes, effectively improve system to the execution efficiency of incoming event, be effectively improved the use of user Experience.
Specific implementation process of the invention is described in further detail below.
Step 401, when detect main thread to incoming event without response when, generate interrupt signal;
Wherein, whether detection main thread responds incoming event in the first preset time.Since user is to interface card Sensation time be 100~200ms, therefore in order to avoid user feels Caton, in the embodiment of the present invention, which is set It sets within 200ms.
Wherein, main thread refers to the user interface main thread of system.The thread android system run when just by Creation, for being responsible for display, update and the widget interaction at the control interface UI.
Wherein, incoming event includes click event, double click event, stroke event etc..In android system, set in advance Event distributor has been set, for incoming event to be distributed in active window, event has specifically been operated by main thread.
Specifically, case distribution device defines incoming event and processing type.When case distribution device receives the defeated of user After incoming event, the processing type of response is called according to incoming event, and the processing type is distributed to movable application widget.
Wherein, the UI of movable application widget, which is updated, is responsible for processing by main thread.Therefore, when receive case distribution device hair After the event type sent, corresponding event handling function is called to be handled according to event type.After to thread process, return Return processing response.If notifying to carry out interrupt processing after the processing response that can't detect main thread in preset detection time.
Wherein, the generation of interrupt signal is done by calling Thread.interrupt () method. Thread.interrupt () method has modified the interrupt status of main thread by obtaining time-out detection signal to inform agency.
Specifically, interrupt processing is not done after time-out detects signal for the main thread in non-obstruction, which is in non- Disconnected state;By calling Thread.isInterrupted () method, interrupt status is returned into true;
For the main thread in abolishable blocked state, for example, etc. pending time-consuming sub thread, Thread.sleep (), Object.wait (), Thread.join () after detecting main thread response timeout, can dish out when interrupting detection InterruptedException, while interrupt status can be put back into as false.
Step 402, it if after detecting interrupt signal, terminates and saves main thread to the treatment progress of incoming event, and start Sub thread.
Wherein, main thread acts on behalf of the access process for acting on behalf of main thread.It is acted on behalf of by main thread and is responsible for maintenance main thread State and function.In the embodiment of the present invention, main thread agency can be realized by Java dynamic proxy mechanism, due to Java dynamic Agency mechanism already belongs to technology well-known to those skilled in the art.Therefore, the specific implementation no longer to main thread agency here It is repeated.
Specifically, when application widget starts, the function that main thread calls all is registered in main thread agency.In event Distributor is distributed to main thread processing incoming event, at this moment main thread is to master when detecting incoming event is main thread process Thread agency, which sends, a proxy requests.Since the function that main thread calls all is registered to main thread agency, main thread is sent After proxy requests, main thread agency will be directed toward the specific calling function of the incoming event.
Wherein, for the acquisition of interrupt module interrupt signal, main thread agency can pass through Thread.isInterrupted () reads main thread interrupt status.Main thread agency get interrupt signal after, will in Disconnected state puts back into as true, and the interrupt status is avoided to have an impact the processing of other threads.One can specifically be passed through The static method of Thread.interrupted () reads and removes interrupt status value.
Wherein, main thread agency detects interrupt signal, terminates main thread in time and continues to handle to incoming event, together Shi Baocun incoming event executes field data.After field data preservation, the reduction of promoter thread process executes scene to not holding The incoming event gone continues to execute.
As can be seen that main thread acts on behalf of the various operations of main thread in the embodiment of the present invention, convenient for capturing terminal letter After number, operation is terminated in time, new trigger event is handled convenient for main thread and is handled;It is directed to interrupt operation simultaneously, saves Behind the execution scene of incoming event, sets up another sub thread reduction execution scene and the operation being not carried out is continued to execute.Therefore, pass through Time-consuming incoming event is transferred to the sub thread on backstage to continue to handle by main thread agency, does not influence the interface operation of user, The interactive experience of user is promoted simultaneously.
Wherein, UI can not directly be updated in usual sub thread.If directly refreshing sub thread, it will usually dish out following different Often.Therefore, after sub thread is disposed, or by the update of main thread completion UI.
Specifically, it after the completion of sub thread handles the subsequent processes of incoming event, is acted on behalf of to main thread and sends notice;Main line After Cheng Daili receives notice, notice main thread updates UI.
Handler, can be with various interactions as the interaction channel between sub thread and main thread.In the embodiment of the present invention, Using handler+message mode, UI is updated by sub thread notice main thread.
Specifically, a Handler processor is pre-created in main thread agency, for monitoring the Message thing of sub thread Part.After group thread process finishes the process of incoming event, state changes, then issues event handling and finish information Message.After Handler processor listens to the Message that incoming event processing is completed, notice main thread updates UI.
Further, referring to Fig. 5, a specific embodiment of the invention avoids processing method of the application program without response Include the following steps:
Step 501, judge whether incoming event is handled by main thread:
When determining that incoming event handles by main thread, step 502 is executed,
If judging, incoming event by non-master thread process, executes step 506;
Step 502, in first event detect main thread to incoming event without response when, generate interrupt signal;
Step 503, if after main thread agency detects interrupt signal, terminate save main thread to the processing of incoming event into Journey, and start sub thread;
Step 504, sub thread handles subsequent processes, after being disposed, sends a message in main thread agency;
Step 505, main thread agency receives message, and main thread is notified to update UI.
Step 506, detect whether incoming event has response within the second response time;Wherein the second response time was greater than the One response time, it is set as 5s.
Step 507, when detecting incoming event within the second response time has response, application program is generated without response ANR Prompt.
As can be seen that avoid application program that the processing method of ANR occurs in the present embodiment, it is main to realize application program master Thread there is a situation where ANR, for the triggering of non-main thread ANR the case where, that is, ANR does not do and locates caused by system trigger Reason, enables the treatment mechanism of system itself effectively to avoid the ANR of main thread while not being destroyed, and that improves user uses body It tests.
In conclusion avoiding processing unit and method of the application program without response provided by the embodiment of the present invention, utilize Timeout module detects the response time of main thread, is sent using interrupt mechanism and executes interrupt signal, in main thread window Agency in interrupt signal carry out capture realize the event handling of main thread is controlled, to reach in operating system Bottom level handles it, and user is avoided frequently to see the bad experience of ANR, to promote operation to a certain extent System is in the in the eyes of stability of user and Experience Degree.
It should be noted that, in this document, the terms "include", "comprise" or its any other variant are intended to non-row His property includes, so that the process, method, article or the device that include a series of elements not only include those elements, and And further include other elements that are not explicitly listed, or further include for this process, method, article or device institute it is intrinsic Element.In the absence of more restrictions, the element limited by sentence "including a ...", it is not excluded that including being somebody's turn to do There is also other identical elements in the process, method of element, article or device.
The serial number of the above embodiments of the invention is only for description, does not represent the advantages or disadvantages of the embodiments.
Through the above description of the embodiments, those skilled in the art can be understood that above-described embodiment side Method can be realized by means of software and necessary general hardware platform, naturally it is also possible to by hardware, but in many cases The former is more preferably embodiment.Based on this understanding, technical solution of the present invention substantially in other words does the prior art The part contributed out can be embodied in the form of software products, which is stored in a storage medium In (such as ROM/RAM, magnetic disk, CD), including some instructions are used so that a terminal device (can be mobile phone, computer, clothes Business device, air conditioner or the network equipment etc.) execute method described in each embodiment of the present invention.
The above is only a preferred embodiment of the present invention, is not intended to limit the scope of the invention, all to utilize this hair Equivalent structure or equivalent flow shift made by bright specification and accompanying drawing content is applied directly or indirectly in other relevant skills Art field, is included within the scope of the present invention.

Claims (4)

1. a kind of avoid processing unit of the application program without response characterized by comprising
First detection module, for sending and notifying to interrupt module when detecting main thread to incoming event without response;
The interrupt module, for generating interrupt signal after receiving the notice of the detection module;
Proxy module saves the main thread to described defeated for terminating after the interrupt signal for detecting the interrupt module The treatment progress of incoming event, and promoter threading models;
The sub thread module, for handling the subsequent processes of the incoming event;
The first detection module is specifically used for:
Detect whether main thread responds incoming event in the first preset time;Wherein, first preset time is small In 200ms;
Described device further includes judgment module, for judging whether the incoming event is handled by main thread;
If the incoming event is handled by main thread, notify that the first detection module is detected;
If the incoming event by non-master thread process, notifies that the second detection module is detected;
Second detection module, for detecting whether the incoming event has response within the second response time;
Cue module, for when second detection module detection is without response, generating application program without response ANR prompt.
2. device as described in claim 1, which is characterized in that the sub thread module is also used at the incoming event After the completion of reason, Xiang Suoshu proxy module sends message;
The proxy module after being also used to receive the message, notifies the main thread more new user interface.
3. a kind of avoid processing method of the application program without response characterized by comprising
When detecting main thread to incoming event without response, interrupt signal is generated;
If terminating after main thread agency detects the interrupt signal and saving processing of the main thread to the incoming event Process, and promoter thread process subsequent processes;
Detect whether main thread responds incoming event in the first preset time;Wherein, first preset time is small In 200ms;
Judge whether the incoming event is handled by main thread;
If the incoming event is handled by main thread, detected in the first preset time the main thread to incoming event whether there is or not Response;
If the incoming event detects whether the incoming event has sound by non-master thread process within the second response time It answers;
When detection is without response, application program is generated without response ANR prompt.
4. method as claimed in claim 3, which is characterized in that the method also includes:
After the incoming event is completed in sub thread processing, is acted on behalf of to main thread and send message;
After the main thread agency receives message, the main thread more new user interface is notified.
CN201610510502.8A 2016-06-30 2016-06-30 It is a kind of to avoid processing unit and method of the application program without response Active CN106155741B (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN201610510502.8A CN106155741B (en) 2016-06-30 2016-06-30 It is a kind of to avoid processing unit and method of the application program without response

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN201610510502.8A CN106155741B (en) 2016-06-30 2016-06-30 It is a kind of to avoid processing unit and method of the application program without response

Publications (2)

Publication Number Publication Date
CN106155741A CN106155741A (en) 2016-11-23
CN106155741B true CN106155741B (en) 2019-10-08

Family

ID=57350910

Family Applications (1)

Application Number Title Priority Date Filing Date
CN201610510502.8A Active CN106155741B (en) 2016-06-30 2016-06-30 It is a kind of to avoid processing unit and method of the application program without response

Country Status (1)

Country Link
CN (1) CN106155741B (en)

Families Citing this family (16)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN106708563B (en) * 2016-11-28 2019-11-26 努比亚技术有限公司 A kind of application program is without response processing method and terminal
CN108345524B (en) * 2017-01-22 2021-12-14 腾讯科技(深圳)有限公司 Application program monitoring method and application program monitoring device
US11392438B2 (en) * 2017-02-09 2022-07-19 Arm Limited Responding to unresponsive processing circuitry
CN106980554B (en) * 2017-03-08 2020-05-26 Oppo广东移动通信有限公司 Process processing method and device
CN108804299B (en) * 2017-04-26 2023-04-07 腾讯科技(深圳)有限公司 Application program exception handling method and device
CN107911227B (en) * 2017-09-28 2020-04-28 平安科技(深圳)有限公司 Breakpoint data follow-up method, electronic device and computer-readable storage medium
CN107861826B (en) * 2017-10-31 2021-05-21 努比亚技术有限公司 Screen freezing monitoring and solving method, mobile terminal and computer readable storage medium
CN108052354A (en) * 2017-11-06 2018-05-18 北京趣拿软件科技有限公司 Definite method, apparatus, processor and terminal of the application program without response
CN108595236A (en) * 2018-03-27 2018-09-28 五八有限公司 A kind of method and device for preventing sub-line journey from carrying out operating user interface
CN109491655B (en) * 2018-10-08 2022-07-15 北京小米移动软件有限公司 Input event processing method and device
CN109947504B (en) * 2019-03-29 2020-12-18 上海连尚网络科技有限公司 Method and equipment for executing hosted program in hosted program
CN111290872A (en) * 2020-01-15 2020-06-16 上海高仙自动化科技发展有限公司 Application program and exception handling method for application program
CN111522764B (en) * 2020-04-07 2023-02-28 Oppo(重庆)智能科技有限公司 Plug-in operation processing method, terminal and storage medium
CN112202960B (en) * 2020-09-27 2022-05-13 广东小天才科技有限公司 Method and device for avoiding no response when intelligent terminal is started and intelligent terminal
CN114185824A (en) * 2021-10-28 2022-03-15 武汉迈威通信股份有限公司 Modbus response processing method and host device
CN114880159B (en) * 2022-07-13 2022-09-13 腾讯科技(深圳)有限公司 Data processing method, device, equipment and storage medium

Citations (4)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN102541605A (en) * 2011-12-30 2012-07-04 Tcl集团股份有限公司 Method and device for picture loading based on Android system
CN103702191A (en) * 2013-12-16 2014-04-02 Tcl集团股份有限公司 Method for avoiding ANR (Application Not Responding) occurring on smart television starter
CN104424094A (en) * 2013-08-26 2015-03-18 腾讯科技(深圳)有限公司 Method and device for obtaining abnormal information and intelligent terminal device
CN105446806A (en) * 2014-09-28 2016-03-30 广州市动景计算机科技有限公司 Processing method and apparatus for application not responding

Patent Citations (4)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN102541605A (en) * 2011-12-30 2012-07-04 Tcl集团股份有限公司 Method and device for picture loading based on Android system
CN104424094A (en) * 2013-08-26 2015-03-18 腾讯科技(深圳)有限公司 Method and device for obtaining abnormal information and intelligent terminal device
CN103702191A (en) * 2013-12-16 2014-04-02 Tcl集团股份有限公司 Method for avoiding ANR (Application Not Responding) occurring on smart television starter
CN105446806A (en) * 2014-09-28 2016-03-30 广州市动景计算机科技有限公司 Processing method and apparatus for application not responding

Also Published As

Publication number Publication date
CN106155741A (en) 2016-11-23

Similar Documents

Publication Publication Date Title
CN106155741B (en) It is a kind of to avoid processing unit and method of the application program without response
CN104735255B (en) Multi-screen display method and system
CN104850799B (en) The method and mobile terminal of a kind of data in hiding mobile terminal
CN105718027A (en) Management method of background application programs and mobile terminal
CN107071760A (en) Data service automatic switching method and mobile terminal
CN104821990B (en) Intelligent terminal realizes the method and intelligent terminal of shutdown alarm clock
CN104866136B (en) A kind of method and device of determining terminal operating mode
CN104850343B (en) Start the method and apparatus of one-hand operating format
CN105138400B (en) Application program self-starting management method and device
CN105764085A (en) Abnormal electricity consumption detection method and terminal
CN107104970A (en) A kind of regular and synchronized processing method, system, rule server and gray scale server
CN106407088A (en) Method and device for detecting multi-core CPU
CN106095464B (en) A kind of method and device of the seamless operation of application program
CN105204992A (en) Test script generating device and method
CN105808049B (en) A kind of control method that realizing mobile terminal and device
CN105050076B (en) Virtual card user interface management method and system
CN106445830A (en) Application program running environment detection method and mobile terminal
CN106406621B (en) A kind of mobile terminal and its method for handling touch control operation
CN105302457B (en) Terminal control method and device
CN105100408B (en) A kind of method and apparatus controlling mobile terminal
CN106484534A (en) Control method for the mobile terminal of displaying and control device
CN106371704A (en) Fast application layout method for lock screen interface and terminal
CN105974437B (en) A kind of method, apparatus and terminal promoting terminal applies performance
CN106941568A (en) A kind of Toast pop-ups optimization display methods, device and Toast pop-ups dispatching method and device
CN107092510A (en) Mobile terminal and its firmware upgrade method and device

Legal Events

Date Code Title Description
C06 Publication
PB01 Publication
C10 Entry into substantive examination
SE01 Entry into force of request for substantive examination
GR01 Patent grant
GR01 Patent grant