MMS portal analysis:
The two most important activities in MMS are:Conversationlist(SMS list), the other isComposemessageactivity(Single conversation or text message ). Each composemessageactivity record belongs to a conversation or does not belong to any conversation (no recipient draft). Each converation is distinguished by an independent threadid. Each converation has a unique workingmessage indicating that this is under thread. The launch mode of conversationlist and composemessageactivity is singletop.
The launch mode of Android involves tasks and activities. Every interface you see is basically an activity, which is put into the task in the form of stacks, for example, the stack import operation is generated by clicking another activity, and the stack exit operation is performed by pressing the back key. The attribute of a task is determined by its first activity, that is, the activity at the bottom of the stack. The launch mode of an activity determines its performance characteristics in the task:
1. The standard mode has no features. You can add any instances in a task and coexist in multiple tasks at the same time.
2. singletask is only one of the mobile phones and must appear at the bottom of the stack of this task.
3. singleinstance indicates that this acitivity occupies the entire task, and this task has only such an activity.
4. singletop is a bit similar to standard. The difference is that he will reuse his own entity at the top layer of the task. For example, ABC is three activities, the mode is standard, in a stack of the arrangement is A-B-C, at this time from C and then a new C intent, task into a A-B-C-C; if the mode of C happens to be singletop, then the top can only be a C, that is, in the A-B-C scenario, when another C, task becomes a-B-c. But now the top C is a brand new C, not the original one.
In addition, the launcher presses the next C icon. At this time, the system will retrieve all the tasks with C as the bottom of the stack. If yes, it will start up. If no, start a new one.
Several important functions in composemessageactivity:
1.OnsaveinstancestateFunction calling is different from onpause () and onstop (), but it can be called before onstop () If composemessageactivity is killed. This function is called when the composemessageactivity ends abnormally and saves some field information, which can restore the scenario when the user leaves.
When workingmessage is initialized, if composemessageactivity saves part of the information during onsaveinstancestate, it will be read from the old contacts, and the contacts will be separated. Workingmessage is also initialized by the previously saved variables. This Initialization is basically complete and is returned.
If it is not saved, read the thread_id value from the input intent to obtain the information required for initialization:
A. thread_id> 0; then mconversation is obtained from the conversation cache by thread_id.
B. thread_id <= 0; then obtain thread_id from the date of the intent. If it is not obtained, it means that this thread has not been used before. Maybe the user is a handwritten address, and a contactlist is generated from the address, match the contactlist with the conversation cache to obtain the corresponding conversation.
At this time, if the match still does not get the conversation, the cache will secretly generate a conversation and return, which is applicable to your situation. Cache is used to ensure that all messages matching contacts are put into the same thread. If the contact is empty, a new conversation is generated directly. This conversation is cheap because it does not have thread_id and is not put into cache. Before using ensurethreadid, he can create numerous, and can call and create them at will.
With conversation, you can initmessagelist and query all the messages under this thread.
2.Handlesendintent ()The function is used to determine whether a intent calls composemessageactivity. The feature is that intent can obtain action and mimetype, such as action_send and action_send_multiple. The file stream, such as extra_stream, and the string extra_text, add attachments directly. Other procedures are similar to messagelist.
3.Handleforwardedmessage ()When a function is not a composemessageactivity called by intent, check whether it is a call initiated by the forwarding. These checks check the keywords contained in intent's extra, such as "forwarded_message" and intent. getaction (), "recipients", "thread_id"
4. There are only two portals for composemessageactivity: oncreate () and onnewintent (). The core of these two initialization functions is initialize (bundle savedinstancestate)
Oncreate () is relatively simple. Its content mainly includes initialization variables, initialization UI, and initialize ().
Onnewintent () only occurs in singletop scenarios, that is, there is already a composemessageactivity at the top of the task (that is, the user's line of sight or hidden to the background ), then, onnewintent will be called when you access the launcher text message or the statusbar text message entry. When onnewintent is called, you need to save the status of the original composemessageactivity and use the information in the new intent to form a new composemessageactivity to replace it. The original intent information is in mconversation and mworkingmessage. For example, mconversation. getthreadid () gets threadid. If threadid is 0, it indicates that the original composemessageactivity contains a draft and needs to be saved. For example, mworkingmessage contains the latest recipient information. You need to copy mworkingmessage. syncworkingrecipients () to conversation. At this time, copy the contact to conversation for saving the draft. Whether the new intent and the original composemessageactivity belong to the same conversation judgment; the only basis for judgment isContact List. The URI of the new intent calls the URI. getschemespecificpart () function to return a sequence of separated phone numbers, which can be assembled into contactlist and a list of new contacts. Through comparison, you can know whether the contactlist between the original and new products is the same. If the comparison is different, the new intent occupies the composemessageactivity. If the comparison is the same, this operation is occupied without changing conversation. This takes three steps:
1. The savedraft () function saves the draft of the original conversation (mrecipientscontainer is synchronized to workingmessage .)
2. The initialize () function, that is, the process mentioned in (I), only the input initialization parameter is null. That is to say, the contact is not provided in bundle during init.
3. loadmessagecontent () function: queries the message status under conversation, initializes the contact information, and draws the related button interface.
Oncreate () entry:
1. Create a New SMS; initialize bundle and intent empty
2. Click a text message in conversation: intent is not empty and initialized by intent.
3. forwarding: When handleforwardedmessage is used, the data in the URI in the intent is retrieved and put into the mworkingmessage, with text and possible mms. Meanwhile, the list cursor is left empty.
4. text messages are sent to files or text files.
Handlesendintent () processing. If the intent contains extra content, you can attach intent. extra_stream or intent. extra_text. The former is a file stream, which can parse multimedia files and the latter is a text. Another type is intent. action_send_multiple.