Disclosure of Invention
Aiming at the defects in the prior art, the invention aims to provide a Handle management method, a storage medium, electronic equipment and a system, which can save the learning and adaptation time of developers and can be used for the direct use period.
In a first aspect, the present invention provides a Handle management method, which is applied to management of a Handle function on Android, and is characterized in that the method includes the following steps:
s1: establishing a template class of an Android-based factory model, wherein parameters of the template class and the subclass of the template class comprise a process of a current class of a request Handle, the Handle and a corresponding relation of the process;
s2: acquiring each request Handle command in the Android system, acquiring a process of the class of the request Handle according to the class of the request Handle, if no subclass is created in the current Android system, entering step S4, otherwise, searching whether the process is contained in the created subclass, if yes, entering step S3, and if not, entering step S4;
s3: checking that the searched subclass has a Handle corresponding to the process in the searched parameters of the subclass, if so, returning to the Handle, and if not, turning to the step S4;
s4: creating a unique Handle for the class of the request Handle and creating a subclass according to the template class.
Preferably, after step S4, the method further includes:
s5: and corresponding to each process, creating a trigger function, and triggering and releasing the Handle in the process when the process is finished running by the trigger function.
Preferably, the Handle name is saved after the unique Handle is created each time, and the trigger function releases the Handle according to the saved Handle name.
Preferably, step S1 specifically includes the following steps:
the method comprises the steps of creating a first class in an Android factory mode, wherein the first class comprises a process name and a second class corresponding to the process name, and the second class comprises the process name and a Handle corresponding to the process name.
Preferably, the step S2 of searching for whether the created subclass includes the process specifically includes:
looking up whether the process is contained in the first class.
Preferably, the step S3 of checking that there is a Handle corresponding to the process in the searched parameters of the subclass specifically includes:
and checking whether a second class in the first class contains a Handle corresponding to the process name or not according to the searched first class.
Preferably, the creating a unique Handle for the class of the request Handle in step S4, and the creating a subclass according to the template class specifically includes:
and creating a unique corresponding Handle for the process, and creating a subclass of the first class according to the corresponding relation.
In a second aspect, the present invention further provides a Handle management system, which includes a creating module, a determining module, and a corresponding module:
the system comprises a creating module, a processing module and a processing module, wherein the creating module is used for creating a template class of an Android-based factory model, and parameters of the template class and the subclass of the template class comprise a process where a current class of a request Handle is located, the Handle and a corresponding relation of the process;
the judging module is used for acquiring each request Handle command in the Android system, acquiring a process of the class of the request Handle according to the class of the request Handle, calling the corresponding module if the subclass is not established in the current Android system, otherwise, searching whether the process is contained in the established subclass, calling the corresponding module if the process is not contained in the established subclass, checking that the process is contained in the searched parameters of the subclass if the process is contained in the searched parameters, returning the Handle if the process is contained in the searched parameters, and corresponding the module if the process is not contained in the searched parameters of the subclass;
and the corresponding module is used for creating a unique Handle for the class of the request Handle and creating a subclass according to the template class.
In a third aspect, an embodiment of the present invention further provides a storage medium, where a computer program is stored on the storage medium, and when being executed by a processor, the computer program implements the method in the embodiment of the first aspect.
In a fourth aspect, an embodiment of the present invention further provides an electronic device, which includes a memory and a processor, where the memory stores a computer program running on the processor, and the processor executes the computer program to implement the method in the first aspect.
Compared with the prior art, the invention has the advantages that:
according to the method, the class in the factory mode is created based on the Android, and openers can directly acquire the corresponding Handle from the factory mode: for the created Handle, subclasses corresponding to the factory classes are created, and developers do not need to manage; for classes of which the handles are not created, the method can create a new Handle return, meanwhile, the method has a corresponding relation to store the corresponding relation, and automatic management of the handles is achieved. Developers do not need to worry about which handles are created for which processes, manual management is not needed, and learning cost is saved. Meanwhile, after the use is finished, the method can release the Handle, developers do not need to spend much energy on maintaining the Handle, leakage is prevented, namely the Handle is released by braking after the life cycle of the process is finished, development of own manual compiling of releasing codes is not needed, and compiling is more efficient and safer.
Detailed Description
Embodiments of the present invention will be described in further detail below with reference to the accompanying drawings.
Referring to fig. 1, embodiments of the present invention provide a Handle management method, a storage medium, an electronic device, and a system, which can save management of a developer on a Handle and debugging time and procedures after an application error by implementing automatic management on the Handle, so that development and compilation of an Android program are more efficient and safer.
In order to achieve the technical effects, the general idea of the application is as follows:
s1: establishing a template class of an Android-based factory model, wherein parameters of the template class and the subclass of the template class comprise a process of a current class of a request Handle, the Handle and a corresponding relation of the process;
s2: acquiring each request Handle command in the Android system, acquiring a process of the class of the request Handle according to the class of the request Handle, if no subclass is created in the current Android system, entering step S4, otherwise, searching whether the process is contained in the created subclass, if yes, entering step S3, and if not, entering step S4;
s3: checking that the searched subclasses have handles corresponding to the processes in the searched subclasses, if yes, returning to the handles, and if not, turning to the step S4;
s4: creating a unique Handle for the class of the request Handle and creating a subclass according to the template class.
In summary, the method records the command of creating or requiring the Handle in the Android system each time, and simultaneously judges whether the current process in the Android system already contains the Handle, if not, the Handle is created, and if yes, the Handle is directly returned.
For processes without a Handle, this method can help the process to uniquely create a corresponding Handle, becoming a process containing a Handle.
For the process with the Handle, the method helps the process with the Handle to establish the corresponding relation, and facilitates direct calling of subsequent program development.
For a programmer, the method is called only when the programmer needs to use the Handle, then the programmer is bound to return the Handle corresponding to the process, the programmer does not need to remember which Handle is used by the process any more, adaptation is not needed according to rules aiming at the Handle, the method is very convenient and fast, and mental labor of developers is reduced.
In order to better understand the technical scheme, the following detailed description is made in conjunction with the specific embodiments.
Example one
As shown in fig. 1, the present invention provides a Handle management method applied to management of a Handle function on Android, which is characterized by comprising the following steps:
s1: establishing a template class of an Android-based factory model, wherein parameters of the template class and the subclass of the template class comprise a process of a current class of a request Handle, the Handle and a corresponding relation of the process;
creating a class in a factory mode, wherein the class uses a plurality of parameters, the parameters comprise a process of a current class of a request Handle, the Handle and a corresponding relation of the process, which is equivalent to making a rule in an Android system, and storing the process and a process-Handle relation table in a unified way.
Every time when a Handle needs to be recorded, the relation can be recorded by creating the subclasses in batch through the class in the factory mode, and meanwhile, because the rules of the class are specified, the created subclasses, namely the subclasses, are always in accordance with the rules, so that the corresponding Handle is conveniently searched in the follow-up process.
S2: acquiring each request Handle command in the Android system, acquiring a process of the class of the request Handle according to the class of the request Handle, if no subclass is created in the current Android system, entering step S4, otherwise, searching whether the created subclass contains the process, if yes, turning to step S3, and if not, turning to step S4;
since the Handle exists in the process, is used by the corresponding process, and is not specific to a specific class, when a certain class in the Android requires the Handle, the process needs to be searched according to the process, so that the process where the request class is located needs to be acquired.
In step S1, a rule for managing handles has been specified, after the current process is obtained, it is necessary to search whether a class created by the template class exists, and if not, it indicates that the current method has not created a corresponding Handle for the process and also has not created a corresponding subclass, so that it is necessary to go to the step of creating a Handle, and if it indicates that the method has created a corresponding relationship for the process, it may go to the next process.
S4: checking whether the subclasses contain handles corresponding to the processes according to the searched subclasses, returning to the handles if the subclasses contain the handles corresponding to the processes, and turning to the step S5 if the subclasses do not contain the handles corresponding to the processes;
after finding out the process in which the class requesting to create the Handle currently is recorded, since in step S1, a format of the parent class about storing the relationship between the process and the Handle is formulated, the subclass of the parent class must meet the rule, at this time, it is only necessary to further find out whether the Handle corresponding to the process is stored in the subclass, if so, it is only necessary to return to the Handle, and if not, it is necessary to enter the process of creating the Handle.
S4: creating a unique Handle for the class of the request Handle and creating a subclass according to the template class.
Step S4 is a step of creating a Handle in the method, and for a case where the Handle cannot be found or the corresponding process relationship of the Handle cannot be found, the Handle corresponding to the process needs to be created while the corresponding relationship between the process and the Handle is stored, so that the method can be directly used in the next call.
Further, after step S4, the method further includes:
s5: and corresponding to each process, creating a trigger function, and triggering and releasing the Handle in the process when the process is finished running by the trigger function.
For developers, calling and creating a Handle are very important in an Android system, and after a process in the Android system is finished, if the Handle is not released in time, problems of program bug, crash, security leakage and the like can be caused.
Therefore, after the process is ended, it is also important to release the Handle for the process, and since the corresponding relationship between the process and the Handle is already created in the above steps S1 to S5, after the process is ended, it is only necessary to search for the Handle corresponding to the process that is ended after the process is ended according to the corresponding relationship, and then release the Handle, that is, in step S6, the Handle is released according to the saved Handle name.
After the process is finished, the process cannot run the corresponding function, so a trigger function is needed, and after the process is finished, the trigger function releases Handle.
Specifically, the trigger function is a subfunction of an actionydestroyed function under application.
Further, step S1 specifically includes the following steps:
the method comprises the steps that a first class is established in an Android factory mode, the class comprises a process name and a second class corresponding to the process name, the second class comprises the process name and a Handle corresponding to the process name, and the subclass is a subclass of the first class.
Specifically, a factory class DYMagicHandle factory that manages DYMagicHandle is created:
HashMap < Integer, HashMap < Integer, DYMagcHandle > > wherein Integer corresponds to process name, DYMagcHandle is Handle name. The first type is HashMap < Integer, HashMap < Integer, DYMagcHandle > >, and the second type is HashMap < Integer, DYMagcHandle >.
The subclass/subclass created from this template class will contain the process name and Handle name.
For example, the subclass/subclass name created according to HashMap < Integer, HashMap < Integer, DYMagicHandle > > is mHandleMaps.
As a preferred scheme, the specific DYMagicHandle method is as follows:
and acquiring the process of the class of the current request Handle.
According to whether the process has the corresponding subclass in mHandleMaps < Integer, HashMap < Integer, DYMaxiHandle >.
And if not, creating a Handle of the corresponding process, and saving the subclass mHandleMaps < Integer, HashMap < Integer, DYMagcHandle > >, according to the template class HashMap < Integer, HashMap < Integer, DYMagcHandle > >.
If the process exists, further searching whether the HashMap < Integer and DYMagcHandle > in the found subclass mHandleMaps < Integer, HashMap < Integer and DYMagcHandle > further finds whether the DYMagcHandle corresponding to the process exists, if so, returning to the Handle, if not, creating a Handle and saving the subclass mHandleMap < Integer, HashMap < Integer and DYMagcHandle > according to the template class HashMap < Integer, HashMap < Integer and DYMagcHandle >.
After the template class is set and the searching mechanism is established, the rule is formulated in the Android system, developers do not need to learn relevant regulations appointed by the Handle any more, the learning cost is saved, and the creation and maintenance can be completed only by calling the method. The workload of the developer is reduced.
Based on the same inventive concept, the present application provides the second embodiment.
Example two
As shown in fig. 2, the present invention also provides a Handle management system, which comprises
The system comprises a creating module, a processing module and a processing module, wherein the creating module is used for creating a template class of an Android-based factory model, and parameters of the template class and the subclass of the template class comprise a process where a current class of a request Handle is located, the Handle and a corresponding relation of the process;
the judging module is used for acquiring each request Handle command in the Android system, acquiring a process of the class of the request Handle according to the class of the request Handle, calling the corresponding module if the subclass is not established in the current Android system, otherwise, searching whether the process is contained in the established subclass, calling the corresponding module if the process is not contained in the established subclass, checking that the process is contained in the searched parameters of the subclass if the process is contained in the searched parameters, returning the Handle if the process is contained in the searched parameters, and corresponding the module if the process is not contained in the searched parameters of the subclass;
and the corresponding module is used for creating a unique Handle for the class of the request Handle and creating a subclass according to the template class.
Various changes and specific examples in the foregoing method embodiments are also applicable to the system in this embodiment, and the implementation method of the system in this embodiment will be clear to those skilled in the art from the foregoing detailed description of the method, so that detailed descriptions thereof are omitted here for the sake of brevity of the description.
Based on the same inventive concept, the present application provides the third embodiment.
EXAMPLE III
A third embodiment of the invention provides a computer-readable storage medium, on which a computer program is stored which, when being executed by a processor, carries out all or part of the method steps of the first embodiment.
The present invention can implement all or part of the flow in the method of the first embodiment, and can also be implemented by using a computer program to instruct related hardware, where the computer program can be stored in a computer-readable storage medium, and when the computer program is executed by a processor, the steps of the method embodiments can be implemented. Wherein the computer program comprises computer program code, which may be in the form of source code, object code, an executable file or some intermediate form, etc. The computer-readable medium may include: any entity or device capable of carrying the computer program code, recording medium, usb disk, removable hard disk, magnetic disk, optical disk, computer Memory, Read-Only Memory (ROM), Random Access Memory (RAM), electrical carrier wave signals, telecommunications signals, software distribution medium, and the like. It should be noted that the computer readable medium may contain content that is subject to appropriate increase or decrease as required by legislation and patent practice in jurisdictions, for example, in some jurisdictions, computer readable media does not include electrical carrier signals and telecommunications signals as is required by legislation and patent practice.
Based on the same inventive concept, the present application provides the fourth embodiment.
Example four
The fourth embodiment of the present invention further provides an electronic device, which includes a memory and a processor, where the memory stores a computer program running on the processor, and the processor executes the computer program to implement all or part of the method steps in the first embodiment.
The Processor may be a Central Processing Unit (CPU), other general purpose Processor, a Digital Signal Processor (DSP), an Application Specific Integrated Circuit (ASIC), an off-the-shelf Programmable Gate Array (FPGA) or other Programmable logic device, discrete Gate or transistor logic, discrete hardware components, etc. The general purpose processor may be a microprocessor or the processor may be any conventional processor or the like which is the control center for the computer device and which connects the various parts of the overall computer device using various interfaces and lines.
The memory may be used to store the computer programs and/or modules, and the processor may implement various functions of the computer apparatus by executing or executing the computer programs and/or modules stored in the memory and calling data stored in the memory. The memory may mainly include a storage program area and a storage data area, wherein the storage program area may store an operating system, an application program required by at least one function (such as a sound playing function, an image playing function, etc.), and the like; the storage data area may store data (such as audio data, video data, etc.) created according to the use of the cellular phone, etc. In addition, the memory may include high speed random access memory, and may also include non-volatile memory, such as a hard disk, a memory, a plug-in hard disk, a Smart Media Card (SMC), a Secure Digital (SD) Card, a Flash memory Card (Flash Card), at least one magnetic disk storage device, a Flash memory device, or other volatile solid state storage device.
Generally, according to the Handle management method, the storage medium, the electronic device and the system provided by the embodiment of the invention, classes in an Android system factory mode are created, and a new Handle is searched and returned or created according to a command for creating the Handle, compared with the traditional technology and the like, developers do not need to manually manage the Handle corresponding to each process, the workload of the developers can be reduced, and the development is more efficient, accurate and safe.
As will be appreciated by one skilled in the art, embodiments of the present invention may be provided as a method, system, or computer program product. Accordingly, the present invention may take the form of an entirely hardware embodiment, an entirely software embodiment or an embodiment combining software and hardware aspects. Furthermore, the present invention may take the form of a computer program product embodied on one or more computer-usable storage media (including, but not limited to, disk storage, optical storage, and the like) having computer-usable program code embodied therein.
The present invention is described with reference to flowchart illustrations and/or block diagrams of methods, apparatus (systems), and computer program products according to embodiments of the invention. It will be understood that each flow and/or block of the flow diagrams and/or block diagrams, and combinations of flows and/or blocks in the flow diagrams and/or block diagrams, can be implemented by computer program instructions. These computer program instructions may be provided to a processor of a general purpose computer, special purpose computer, embedded processor, or other programmable data processing apparatus to produce a machine, such that the instructions, which execute via the processor of the computer or other programmable data processing apparatus, create means for implementing the functions specified in the flowchart flow or flows and/or block diagram block or blocks.
These computer program instructions may also be stored in a computer-readable memory that can direct a computer or other programmable data processing apparatus to function in a particular manner, such that the instructions stored in the computer-readable memory produce an article of manufacture including instruction means which implement the function specified in the flowchart flow or flows and/or block diagram block or blocks.
These computer program instructions may also be loaded onto a computer or other programmable data processing apparatus to cause a series of operational steps to be performed on the computer or other programmable apparatus to produce a computer implemented process such that the instructions which execute on the computer or other programmable apparatus provide steps for implementing the functions specified in the flowchart flow or flows and/or block diagram block or blocks.
It will be apparent to those skilled in the art that various changes and modifications may be made in the present invention without departing from the spirit and scope of the invention. Thus, if such modifications and variations of the present invention fall within the scope of the claims of the present invention and their equivalents, the present invention is also intended to include such modifications and variations.