CN109246177B - Method for designing asynchronous communication tool in Android - Google Patents

Method for designing asynchronous communication tool in Android Download PDF

Info

Publication number
CN109246177B
CN109246177B CN201810724905.1A CN201810724905A CN109246177B CN 109246177 B CN109246177 B CN 109246177B CN 201810724905 A CN201810724905 A CN 201810724905A CN 109246177 B CN109246177 B CN 109246177B
Authority
CN
China
Prior art keywords
dyhandler
cls
class
function
calling
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
CN201810724905.1A
Other languages
Chinese (zh)
Other versions
CN109246177A (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.)
Wuhan Douyu Network Technology Co Ltd
Original Assignee
Wuhan Douyu Network 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 Wuhan Douyu Network Technology Co Ltd filed Critical Wuhan Douyu Network Technology Co Ltd
Priority to CN201810724905.1A priority Critical patent/CN109246177B/en
Publication of CN109246177A publication Critical patent/CN109246177A/en
Application granted granted Critical
Publication of CN109246177B publication Critical patent/CN109246177B/en
Active legal-status Critical Current
Anticipated expiration legal-status Critical

Links

Images

Classifications

    • HELECTRICITY
    • H04ELECTRIC COMMUNICATION TECHNIQUE
    • H04LTRANSMISSION OF DIGITAL INFORMATION, e.g. TELEGRAPHIC COMMUNICATION
    • H04L69/00Network arrangements, protocols or services independent of the application payload and not provided for in the other groups of this subclass
    • H04L69/03Protocol definition or specification 
    • 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/46Multiprogramming arrangements
    • G06F9/50Allocation of resources, e.g. of the central processing unit [CPU]
    • G06F9/5005Allocation of resources, e.g. of the central processing unit [CPU] to service a request
    • G06F9/5011Allocation of resources, e.g. of the central processing unit [CPU] to service a request the resources being hardware resources other than CPUs, Servers and Terminals
    • G06F9/5022Mechanisms to release resources
    • HELECTRICITY
    • H04ELECTRIC COMMUNICATION TECHNIQUE
    • H04LTRANSMISSION OF DIGITAL INFORMATION, e.g. TELEGRAPHIC COMMUNICATION
    • H04L67/00Network arrangements or protocols for supporting network services or applications
    • H04L67/34Network arrangements or protocols for supporting network services or applications involving the movement of software or configuration parameters 

Landscapes

  • Engineering & Computer Science (AREA)
  • Computer Networks & Wireless Communication (AREA)
  • Signal Processing (AREA)
  • Software Systems (AREA)
  • Theoretical Computer Science (AREA)
  • Computer Security & Cryptography (AREA)
  • Physics & Mathematics (AREA)
  • General Engineering & Computer Science (AREA)
  • General Physics & Mathematics (AREA)
  • Mobile Radio Communication Systems (AREA)

Abstract

The invention provides a design method of an asynchronous communication tool in Android, which comprises the following steps: defining a DyHandler class; defining a getDyHandler (class cls) function for producing DyHandler objects; defining a Map set for representing the mapping relation between cls and DyHandler classes; when the DyHandler object is generated according to cls, judging whether the cls exists in a Map set or not, calling a getDyHandler (class cls) function to obtain the DyHandler object if the cls exists in the Map set, and otherwise, calling a construction function of a DyHandler class to obtain the DyHandler object; when the dyHandler object is no longer used, the dyHandler object is deleted from the Map set. The method solves the problems of tedious use of the Handler and memory leakage.

Description

Method for designing asynchronous communication tool in Android
Technical Field
The disclosure relates to the technical field of communication, in particular to a method for designing an asynchronous communication tool in Android.
Background
In the traditional scheme, asynchronous communication uses a Handler tool class provided by an Android system for communication, and due to the problems that handlers are frequently used, instanced objects need to be instantiated, message callback is required to be processed and the like in the scheme, the use of the Handler tool class is very complicated, and when a message cannot be released in time, the problem of memory leakage is easily caused, so that a large amount of memory is occupied without being released, other services cannot be applied to corresponding memory space, and abnormality occurs.
Disclosure of Invention
Aiming at the technical problems in the prior art in the traditional scheme, the invention provides a design method of an asynchronous communication tool in an Android system and Android electronic equipment, which are used for solving the problems that asynchronous communication is complicated to use due to great difficulty in using a Handler in the traditional scheme, and memory leakage is caused by untimely message release in the Handler, so that a large amount of memory is occupied, and other services cannot be applied to corresponding memory space.
The invention provides a design method of an asynchronous communication tool in an Android system, which comprises the following steps: defining a DyHandler class; defining a getDyHandler (class cls) function for generating a DyHandler object, wherein the cls is a calling parameter for generating the DyHandler object; defining a Map set, wherein an mMap object of the Map set is used for representing a mapping relation between the calling parameter cls and a DyHandler object generated according to the calling parameter cls; when a DyHandler object is generated according to calling parameter cls, judging whether the calling parameter cls exists in an mMap object of the Map set, if so, calling a getDyHandler (class cls) function to obtain the DyHandler object, otherwise, calling a construction function of a DyHandler class to obtain the DyHandler object; deleting the DyHandler object from the mMap object when the DyHandler object is no longer used.
Optionally, the dyHandler class includes a protocol stack for message transmission and an object mListener for message transmission, the object mListener is assigned as a parameter listener, a reference relationship between the object mListener and a message acceptance of a call function is constructed, and then the message is transmitted to an object for calling the function through the protocol stack.
Optionally, the getdyHandler (class cls) function is a static function in the DyHandler class.
Optionally, when a getdyHandler (class cls) function is called to obtain a dyHandler object, judging whether the calling parameter cls is empty, if so, returning, and otherwise, obtaining the dyHandler object.
Optionally, deleting the dyHandler object from the mMap object includes: the dyHandler object is released by calling the mMap.
Another aspect of the present disclosure provides an Android electronic device, including: a processor and a memory, the memory storing a computer executable program that, when executed by the processor, causes the processor to perform: defining a DyHandler class; defining a getDyHandler (class cls) function for generating a DyHandler object, wherein the cls is a calling parameter for generating the DyHandler object; defining a Map set, wherein an mMap object of the Map set is used for representing a mapping relation between the calling parameter cls and a DyHandler object generated according to the calling parameter cls; when a DyHandler object is generated according to calling parameter cls, judging whether the calling parameter cls exists in an mMap object of the Map set, if so, calling a getDyHandler (class cls) function to obtain the DyHandler object, otherwise, calling a construction function of a DyHandler class to obtain the DyHandler object; deleting the DyHandler object from the mMap object when the DyHandler object is no longer used.
Optionally, the processor assigns the object mListener to a parameter listener, constructs a reference relationship between the object mListener and a message of a calling function, and transmits the message to the object of the calling function through a protocol stack.
Optionally, the getdyHandler (class cls) function is a static function in the DyHandler class.
Optionally, when the processor calls a getdyHandler (class cls) function to obtain a dyHandler object, judging whether the calling parameter cls is empty, if so, returning, and otherwise, obtaining the dyHandler object.
Optionally, deleting, at the processor, the dyHandler object from the mMap object, including: the dyHandler object is released by calling the mMap.
The design method solves the problem that a Handler in the traditional scheme is complex to use, effectively improves convenience of asynchronous communication use, meanwhile effectively ensures that a system memory can be normally released, and solves the problem that the memory is occupied in a large amount to cause that other services cannot apply for corresponding memory space due to memory leakage caused by untimely message release.
Drawings
For a more complete understanding of the present disclosure and the advantages thereof, reference is now made to the following descriptions taken in conjunction with the accompanying drawings, in which:
fig. 1 schematically shows a flowchart of a method for designing an asynchronous communication tool in an Android system, provided by the embodiment of the disclosure.
Fig. 2 schematically shows an Android electronic device provided according to an embodiment of the present disclosure.
Detailed Description
Hereinafter, embodiments of the present disclosure will be described with reference to the accompanying drawings. It should be understood that the description is illustrative only and is not intended to limit the scope of the present disclosure. In the following detailed description, for purposes of explanation, numerous specific details are set forth in order to provide a thorough understanding of the embodiments of the disclosure. It may be evident, however, that one or more embodiments may be practiced without these specific details. Moreover, in the following description, descriptions of well-known structures and techniques are omitted so as to not unnecessarily obscure the concepts of the present disclosure.
The terminology used herein is for the purpose of describing particular embodiments only and is not intended to be limiting of the disclosure. The terms "comprises," "comprising," and the like, as used herein, specify the presence of stated features, steps, operations, and/or components, but do not preclude the presence or addition of one or more other features, steps, operations, or components.
All terms (including technical and scientific terms) used herein have the same meaning as commonly understood by one of ordinary skill in the art unless otherwise defined. It is noted that the terms used herein should be interpreted as having a meaning that is consistent with the context of this specification and should not be interpreted in an idealized or overly formal sense.
Where a convention analogous to "A, B or at least one of C, etc." is used, in general such a construction is intended in the sense one having skill in the art would understand the convention (e.g., "a system having at least one of A, B or C" would include but not be limited to systems that have a alone, B alone, C alone, a and B together, a and C together, B and C together, and/or A, B, C together, etc.). It will be further understood by those within the art that virtually any disjunctive word and/or phrase presenting two or more alternative terms, whether in the description, claims, or drawings, should be understood to contemplate the possibilities of including one of the terms, either of the terms, or both terms. For example, the phrase "a or B" should be understood to include the possibility of "a" or "B", or "a and B".
Some block diagrams and/or flow diagrams are shown in the figures. It will be understood that some blocks of the block diagrams and/or flowchart illustrations, or combinations thereof, 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, or other programmable data processing apparatus, such that the instructions, which execute via the processor, create means for implementing the functions/acts specified in the block diagrams and/or flowchart block or blocks.
Accordingly, the techniques of this disclosure may be implemented in hardware and/or software (including firmware, microcode, etc.). In addition, the techniques of this disclosure may take the form of a computer program product on a computer-readable medium having instructions stored thereon for use by or in connection with an instruction execution system. In the context of this disclosure, a computer-readable medium may be any medium that can contain, store, communicate, propagate, or transport the instructions. For example, the computer readable medium can include, but is not limited to, an electronic, magnetic, optical, electromagnetic, infrared, or semiconductor system, apparatus, device, or propagation medium. Specific examples of the computer readable medium include: magnetic storage devices, such as magnetic tape or Hard Disk Drives (HDDs); optical storage devices, such as compact disks (CD-ROMs); a memory, such as a Random Access Memory (RAM) or a flash memory; and/or wired/wireless communication links.
The embodiment of the disclosure provides a method for realizing an asynchronous communication tool in an Android system, which comprises the following steps: defining a DyHandler class; defining a getDyHandler (class cls) function for generating a DyHandler object, wherein the cls is a calling parameter for generating the DyHandler object; defining a Map set, wherein an mMap object of the Map set is used for representing a mapping relation between a calling parameter cls and a DyHandler class generated according to the calling parameter cls; when a DyHandler object is generated according to calling parameter cls, judging whether the calling parameter cls exists in an mMap object of a Map set, if so, calling a getDyHandler (class cls) function to obtain the DyHandler object, otherwise, calling a construction function of a DyHandler class to obtain the DyHandler object; the dyHandler object is deleted from the mMap object when the dyHandler object is no longer used.
Fig. 1 schematically shows a flowchart of a method for designing an asynchronous communication tool in an Android system, provided by the embodiment of the disclosure.
As shown in fig. 1, the specific method includes the following operations:
and S1, defining a DyHandler class, wherein the object of the DyHandler class has an asynchronous communication function.
In the above operation S1, a public class DyHandler < T > extensions Handler method is specifically used to define a DyHandler class, so that the DyHandler class inherits a Handler class provided by an Android system, where when the DyHandler class is defined, a generic parameter T is provided for the DyHandler by using a generic technology, and this way of providing the generic parameter T during definition facilitates corresponding constraint and operation on T in a subsequent implementation process.
In addition, a message transparent protocol stack messageLister is defined in the DyHandler class and is used for designing the transparent transmission of the related messages of the system Handler in the later period, the protocol stack is consistent with the protocol stack for the transparent transmission of the messages of the system Handler, and the specific design method is as follows:
public interface MessageListener{
void magicHandleMessage(Message msg)
}
the protocol stack Message Lister comprises a unique protocol method magicHandleMessage, the protocol method magicHandleMessage comprises a Message type parameter, and a return value is void, namely the design of the transparent transmission protocol needs to ensure the following characteristics: one is that the return value is void, and the other is that the parameter of the entry parameter must be the parameter of the Message type, so the protocol method keeps consistent on the entry and return results, and the subsequent Message transparent transmission design can be ensured.
Meanwhile, an object mListener of the transparent transmission protocol, namely an object of message transmission, is further defined in a DyHandler class, the specific definition method is DyHandler. The specific definition is as follows:
public void setOnMessageListener(DyHandler.MessageListener listener){
this.mListener=listener;
}
through the method, the reference relation between the object mListener and the message acceptance of the calling function is realized, and finally, the message is transmitted to the object of the calling function through the protocol stack MessageListener.
S2, defining getdyhandler (class cls) function for generating DyHandler object, wherein cls is calling parameter for generating DyHandler object.
In the above operation S2, a public Class DyHandler getDyHandler (Class) { } function creation DyHandler object, which is named getDyHandler, is constructed. Because the constructed function is a public function, other functions have the authority of calling the function, and the function is a static function, the function can be directly called through classes without objects, and the calling convenience is improved.
In addition, the getdyHandler function contains a return value of a DyHandler type to return the produced DyHandler object, and has a class-type parameter cls for generating call parameters of the DyHandler object. The concrete implementation of the getDyHandler function is: firstly, judging whether cls is null or not, specifically, judging by calling cls to null, if the value of the expression is true, indicating that cls is null, otherwise, indicating that cls is non-null, if null is returned directly through return, and if not, performing the next construction.
And S3, defining a Map set, wherein the mMap object of the Map set is used for representing the mapping relation between the calling parameter cls and the DyHandler object generated according to the calling parameter cls.
In operation S3, the method for specifically defining the Map set is Map < Class DyHandler > mMap, where the set includes two generic parameters of Class and DyHandler types, and the design is mainly used to construct a mapping relationship between a call parameter cls and a DyHandler Class generated according to the call parameter cls, so as to avoid multiple instantiations of multiple objects.
In addition, when the mMap needs to be instantiated, the specific party instantiation method is that the constructor Map of the HashMap is called, wherein the constructor Map is the Class DyHandler > mMap, and the new HashMap is the Class DyHandler; to instantiate it.
S4, when the DyHandler object is generated according to the calling parameter cls, judging whether the calling parameter cls exists in the mMap object of the Map set, if so, calling a getDyHandler (class cls) function to obtain the DyHandler object, otherwise, calling a construction function of the DyHandler class to obtain the DyHandler object.
In operation S4, it is determined whether a DyHandler object corresponding to class has been instantiated in the mMap object, that is, whether a call parameter cls exists in the mMap object. Judging whether cls is empty or not, returning if the cls is null, otherwise judging whether cls exists in an mMap object by adopting an mMap.contacts (cls) method, if the function return value is true, indicating that a DyHandler object is instantiated, directly calling an mMap.get (cls) method to take the instantiated mDyHandler object, then returning the instantiated mDyHandler object, if the function return value is false, indicating that the DyHandler object corresponding to the class has not been instantiated, calling a DyHandler construction function to instantiate the DyHandler object, specifically, calling a dyHandler mDyHandler-new DyHandler ('), and then returning the instantiated mDyHandler object to the mDyHandler object by calling the mDyHandler construction function and storing the mDyHandler-parameter mDyHandler mapping relation of the instantiated mDyHandler and the mDyHandler object in the mMap.
S5, deleting the dyHandler object from the mMap object when the dyHandler object is no longer used.
In the above operation S5, the DyHandler object is released by calling an mMap-remove (cls) method in the mMap object, so that the DyHandler object of the cls object is prevented from being held by the mMap object, and the reference relationship between the DyHandler object and the mMap object is broken, so that a garbage collection mechanism of the system can collect and process the DyHandler object at an appropriate time, thereby preventing the problem of memory leakage, ensuring that a system memory can be normally released, preventing the system from having a memory shortage problem, and applying other services to a corresponding memory space.
In summary, the present disclosure provides a method for designing an asynchronous communication tool in Android and an Android electronic device, where the method includes: defining a DyHandler class; defining a getDyHandler (class cls) function for generating a DyHandler object, wherein the cls is a calling parameter for generating the DyHandler object; defining a Map set, wherein an mMap object of the Map set is used for representing a mapping relation between the calling parameter cls and a DyHandler object generated according to the calling parameter cls; when a DyHandler object is generated according to calling parameter cls, judging whether the calling parameter cls exists in an mMap object of the Map set, if so, calling a getDyHandler (class cls) function to obtain the DyHandler object, otherwise, calling a construction function of a DyHandler class to obtain the DyHandler object; when the DyHandler object is not used any more, the DyHandler object is deleted from the mMap object, and through the series of design means, the problem that the use of the Handler in the traditional scheme is complicated is solved, the convenience of asynchronous communication use is effectively improved, meanwhile, the normal release of a system memory is effectively ensured, and the problem that the memory is greatly occupied due to the fact that the message is not released in time, and other services cannot apply for corresponding memory space due to the fact that the memory is greatly occupied due to the fact that the memory is leaked is solved.
It should be noted that fig. 1 is only an example of a scenario in which the embodiments of the present disclosure may be applied to help those skilled in the art understand the technical content of the present disclosure, but does not mean that the embodiments of the present disclosure may not be applied to other devices, systems, environments or scenarios.
The present disclosure provides an Android electronic device for asynchronous communication, as shown in fig. 2, the Android electronic device 200 includes a processor 210 and a computer-readable storage medium 220. The Android electronic device 200 may perform the method according to the embodiment of the present disclosure shown in fig. 1.
In particular, processor 210 may include, for example, a general purpose microprocessor, an instruction set processor and/or related chip set and/or a special purpose microprocessor (e.g., an Application Specific Integrated Circuit (ASIC)), and/or the like. The processor 210 may also include onboard memory for caching purposes. Processor 210 may be a single processing unit or a plurality of processing units for performing different actions of a method flow according to embodiments of the present disclosure.
Computer-readable storage medium 220 may be, for example, any medium that can contain, store, communicate, propagate, or transport the instructions. For example, a readable storage medium may include, but is not limited to, an electronic, magnetic, optical, electromagnetic, infrared, or semiconductor system, apparatus, device, or propagation medium. Specific examples of the readable storage medium include: magnetic storage devices, such as magnetic tape or Hard Disk Drives (HDDs); optical storage devices, such as compact disks (CD-ROMs); a memory, such as a Random Access Memory (RAM) or a flash memory; and/or wired/wireless communication links.
The computer-readable storage medium 220 may include a computer program 221, which computer program 221 may include code/computer-executable instructions that, when executed by the processor 210, cause the processor 210 to perform a method according to an embodiment of the disclosure, or any variation thereof.
The computer program 221 may be configured with computer program code, for example, comprising computer program modules. For example, in an example embodiment, code in computer program 221 may include at least one program module, including, for example, module 221A, module 221B, … …. It should be noted that the division and number of the modules are not fixed, and those skilled in the art may use suitable program modules or program module combinations according to actual situations, so that the processor 210 may execute the method according to the embodiment of the present disclosure or any variation thereof when the program modules are executed by the processor 210.
Methods according to embodiments of the present disclosure computer readable media may be computer readable signal media or computer readable storage media or any combination of the two according to embodiments of the present disclosure. A computer readable storage medium may be, for example, but not limited to, an electronic, magnetic, optical, electromagnetic, infrared, or semiconductor system, apparatus, or device, or any combination of the foregoing. More specific examples of the computer readable storage medium may include, but are not limited to: an electrical connection having one or more wires, a portable computer diskette, a hard disk, a Random Access Memory (RAM), a read-only memory (ROM), an erasable programmable read-only memory (EPROM or flash memory), an optical fiber, a portable compact disc read-only memory (CD-ROM), an optical storage device, a magnetic storage device, or any suitable combination of the foregoing. In the present disclosure, a computer readable storage medium may be any tangible medium that can contain, or store a program for use by or in connection with an instruction execution system, apparatus, or device. In contrast, in the present disclosure, a computer-readable signal medium may include a propagated data signal with computer-readable program code embodied therein, for example, in baseband or as part of a carrier wave. Such a propagated data signal may take many forms, including, but not limited to, electro-magnetic, optical, or any suitable combination thereof. A computer readable signal medium may also be any computer readable medium that is not a computer readable storage medium and that can communicate, propagate, or transport a program for use by or in connection with an instruction execution system, apparatus, or device. Program code embodied on a computer readable medium may be transmitted using any appropriate medium, including but not limited to: wireless, wired, optical fiber cable, radio frequency signals, etc., or any suitable combination of the foregoing.
The flowchart and block diagrams in the figures illustrate the architecture, functionality, and operation of possible implementations of systems, methods and computer program products according to various embodiments of the present disclosure. In this regard, each block in the flowchart or block diagrams may represent a module, segment, or portion of code, which comprises one or more executable instructions for implementing the specified logical function(s). It should also be noted that, in some alternative implementations, the functions noted in the block may occur out of the order noted in the figures. For example, two blocks shown in succession may, in fact, be executed substantially concurrently, or the blocks may sometimes be executed in the reverse order, depending upon the functionality involved. It will also be noted that each block of the block diagrams or flowchart illustration, and combinations of blocks in the block diagrams or flowchart illustration, can be implemented by special purpose hardware-based systems which perform the specified functions or acts, or combinations of special purpose hardware and computer instructions.
Those skilled in the art will appreciate that various combinations and/or combinations of features recited in the various embodiments and/or claims of the present disclosure can be made, even if such combinations or combinations are not expressly recited in the present disclosure. In particular, various combinations and/or combinations of the features recited in the various embodiments and/or claims of the present disclosure may be made without departing from the spirit or teaching of the present disclosure. All such combinations and/or associations are within the scope of the present disclosure.
While the disclosure has been shown and described with reference to certain exemplary embodiments thereof, it will be understood by those skilled in the art that various changes in form and details may be made therein without departing from the spirit and scope of the disclosure as defined by the appended claims and their equivalents. Accordingly, the scope of the present disclosure should not be limited to the above-described embodiments, but should be defined not only by the appended claims, but also by equivalents thereof.

Claims (8)

1. A method for realizing an asynchronous communication tool in an Android system comprises the following steps:
s1, defining a DyHandler class, wherein the DyHandler class has an asynchronous communication function, the DyHandler class comprises a protocol stack for message transmission and an object mListener for message transmission, assigning the object mListener as a parameter listener, constructing a reference relation between the object mListener and a call function message, and transmitting the message to an object for calling a function through the protocol stack;
s2, defining a getDyHandler (class cls) function for generating the DyHandler object, wherein the cls is a calling parameter for generating the DyHandler object;
s3, defining a Map set, wherein an mMap object of the Map set is used for representing the mapping relation between the calling parameter cls and a DyHandler object generated according to the calling parameter cls;
s4, when a DyHandler object is generated according to calling parameter cls, judging whether the calling parameter cls exists in an mMap object of the Map set, if so, calling a getDyHandler (class cls) function to obtain the DyHandler object, otherwise, calling a construction function of a DyHandler class to obtain the DyHandler object;
s5, deleting the dyHandler object from the mMap object when the dyHandler object is no longer used.
2. The method of claim 1, further comprising: the getDyHandler (class cls) function is a static function in the DyHandler class.
3. The method of claim 1, further comprising: in operation S4, when the getdyhandler (class cls) function is called to obtain the DyHandler object, it is determined whether the call parameter cls is empty, if so, the call parameter cls is returned, otherwise, the DyHandler object is obtained.
4. The method of claim 1, further comprising: in operation S5, deleting the DyHandler object from the mMap object includes:
the dyHandler object is released by calling the mMap.
5. An Android electronic device, comprising:
a processor;
a memory storing a computer executable program that, when executed by the processor, causes the processor to perform:
s1, defining a DyHandler class, wherein the DyHandler class has an asynchronous communication function, the DyHandler class comprises a protocol stack for message transmission and an object mListener for message transmission, the processor assigns the object mListener as a parameter listener, constructs a reference relation between the object mListener and a call function message, and transmits the message to an object for calling a function through the protocol stack;
s2, defining a getDyHandler (class cls) function for generating the DyHandler object, wherein the cls is a calling parameter for generating the DyHandler object;
s3, defining a Map set, wherein an mMap object of the Map set is used for representing the mapping relation between the calling parameter cls and a DyHandler object generated according to the calling parameter cls;
s4, when a DyHandler object is generated according to calling parameter cls, judging whether the calling parameter cls exists in an mMap object of the Map set, if so, calling a getDyHandler (class cls) function to obtain the DyHandler object, otherwise, calling a construction function of a DyHandler class to obtain the DyHandler object;
s5, deleting the dyHandler object from the mMap object when the dyHandler object is no longer used.
6. The electronic device of claim 5, further comprising: the getDyHandler (class cls) function is a static function in the DyHandler class.
7. The electronic device of claim 5, further comprising: and when the processor calls a getDyHandler (class cls) function to obtain a DyHandler object, judging whether the calling parameter cls is empty, if so, returning, and otherwise, obtaining the DyHandler object.
8. The electronic device of claim 5, further comprising: deleting, at a processor, the DyHandler object from the mMap object, including:
the dyHandler object is released by calling the mMap.
CN201810724905.1A 2018-07-04 2018-07-04 Method for designing asynchronous communication tool in Android Active CN109246177B (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN201810724905.1A CN109246177B (en) 2018-07-04 2018-07-04 Method for designing asynchronous communication tool in Android

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN201810724905.1A CN109246177B (en) 2018-07-04 2018-07-04 Method for designing asynchronous communication tool in Android

Publications (2)

Publication Number Publication Date
CN109246177A CN109246177A (en) 2019-01-18
CN109246177B true CN109246177B (en) 2021-04-27

Family

ID=65071708

Family Applications (1)

Application Number Title Priority Date Filing Date
CN201810724905.1A Active CN109246177B (en) 2018-07-04 2018-07-04 Method for designing asynchronous communication tool in Android

Country Status (1)

Country Link
CN (1) CN109246177B (en)

Citations (5)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN105373548A (en) * 2014-08-25 2016-03-02 腾讯科技(深圳)有限公司 Mobile device and event self-definition method for browser of mobile device
CN106598725A (en) * 2016-10-31 2017-04-26 武汉斗鱼网络科技有限公司 Android-based Handler memory leakage prevention device and method
CN107463380A (en) * 2017-08-01 2017-12-12 武汉斗鱼网络科技有限公司 Message treatment method, device and electronic equipment
CN107515792A (en) * 2017-07-27 2017-12-26 北京五八信息技术有限公司 The method and apparatus that function class carries out Message Processing using Handler
CN108052388A (en) * 2017-11-24 2018-05-18 武汉斗鱼网络科技有限公司 Method for recovering internal storage and device in a kind of Android

Family Cites Families (1)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US20100088187A1 (en) * 2008-09-24 2010-04-08 Chris Courtney System and method for localized and/or topic-driven content distribution for mobile devices

Patent Citations (5)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN105373548A (en) * 2014-08-25 2016-03-02 腾讯科技(深圳)有限公司 Mobile device and event self-definition method for browser of mobile device
CN106598725A (en) * 2016-10-31 2017-04-26 武汉斗鱼网络科技有限公司 Android-based Handler memory leakage prevention device and method
CN107515792A (en) * 2017-07-27 2017-12-26 北京五八信息技术有限公司 The method and apparatus that function class carries out Message Processing using Handler
CN107463380A (en) * 2017-08-01 2017-12-12 武汉斗鱼网络科技有限公司 Message treatment method, device and electronic equipment
CN108052388A (en) * 2017-11-24 2018-05-18 武汉斗鱼网络科技有限公司 Method for recovering internal storage and device in a kind of Android

Non-Patent Citations (3)

* Cited by examiner, † Cited by third party
Title
An experience on multithreading using Android"s handler class;Victor Matos,Rebecca Grasser;《Journal of Computing Sciences in Colleges》;20141031;第30卷(第1期);全文 *
Android性能优化之内存泄漏处理;aserbao;《CSDN博客》;20180321;全文 *
试析Android 异步通信机制;钟键;《电脑编程技巧与维护》;20160531(第10期);全文 *

Also Published As

Publication number Publication date
CN109246177A (en) 2019-01-18

Similar Documents

Publication Publication Date Title
CN109032706B (en) Intelligent contract execution method, device, equipment and storage medium
US20190324772A1 (en) Method and device for processing smart contracts
US20170052884A1 (en) Generic test automation for restful web services applications
CN112416632B (en) Event communication method and device, electronic equipment and computer readable medium
US10216553B2 (en) Message oriented middleware with integrated rules engine
US9710575B2 (en) Hybrid platform-dependent simulation interface
CN109739487B (en) Business logic processing method and device and computer readable storage medium
CN110795143A (en) Method, apparatus, computing device, and medium for processing functional module
CN109683992B (en) Method and apparatus for managing objects
CN109246177B (en) Method for designing asynchronous communication tool in Android
CN109144477B (en) Method for automatically managing class object memory and electronic equipment
US10360403B2 (en) Cognitive API policy manager
CN110674050B (en) Memory out-of-range detection method and device, electronic equipment and computer storage medium
CN110968147B (en) Timer creating method and device, electronic equipment and medium
EP3188071B1 (en) Application accessing control method and device
JP2023021137A (en) Deterministic replay of event between software entities
CN115934378A (en) Service data processing method and device, electronic equipment and storage medium
CN110968382A (en) Method, system, electronic device and medium for updating view
CN113014650B (en) Processing method and device for data request, computing equipment and medium
CN115373869A (en) Process processing method and device based on AAR and electronic equipment
CN112068814A (en) Method, device, system and medium for generating executable file
CN111324386A (en) Method and device for starting personal application program, electronic equipment and storage medium
CN115225916B (en) Video processing method, device and equipment
CN116502215A (en) User-based service isolation method, device, equipment and medium
CN110647405A (en) System message processing method, electronic device, and computer-readable storage medium

Legal Events

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