How to transfer Android data

Source: Internet
Author: User

In Android , data transfer betweenActivity is somewhat complex, such as through Intent and bundles and so on, it must be implemented when passing complex objects. Serializable interface classes, which in many cases make it inconvenient to handle data passing between pages. In Javaweb , thesession object to pass data is very practical and convenient, in this, in Android can be implemented in a similar javaweb in the session it?

In fact, very simple, in the case of not rigorous, the specific implementation process is as follows:

/*/////////////////////////////////////////////////////////////////_ooooo_ O8888888o 88 ". "88 (|                                                      ^_^ |)                                               o\ =/o ____/'---' \____  .'     \\|                                            |//  `.  /  \\||| :  ||| //  \                                         /  _||||| -:- |||||   -  \                                        | |   \\\  -  /// |                                        | |  \_|   ''\---/''  |                                        | \  .-\__  `-`  ___/-. /                                       ___`.  .' /--.--\  `. . ___                                   .""  ' < '. ___\_<|>_/___. '                           > ' "". | | :  `- \`.; `\ _ /`;. `/ - ` : | |   \  \ `-.                                    \_ __\ /__ _/   .-` /  /                      ========`-.____`-.___\_____/___.-`____.-'========                            `=---='                                    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Buddha bless never Bug Code by [email protected]/////// */package Cn.geekduxu.android;import Java.util.HashMap; Import java.util.map;/** * Simulate Javaweb session in Android * @author <a href= "mailto://[email protected" > Douxu </a> */public class Session {private static session instance;private Map<string, object> map;private session ( {map = new hashmap<string, object> ();}  /** * Gets a reference to session object * @return Session object */public static synchronized session getsession () {if (null = = INSTANCE) {INSTANCE = New Session ();} return INSTANCE;} /** * Save value to session * @param key-with specifiedThe value associated with the key * @param value-the value associated with the specified key */public void put (String key, Object value) {map.put (key, value);} /** * Gets the object saved in session * @param key to return its associated value * @return The value mapped by the specified key, or null if the mapping of the key is not included */public object get (String key) {RET Urn Map.get (key);} /** * Remove an object from the session * @param key to remove the object's key * @return the object removed (String key) {return map.remove (key);} /** * Empty session */public void Clear () {map.clear ();}}
This makes it possible toAndroidA simple simulation ofJavawebInSessioneffect, it is much easier to pass the data. (The code in the example is not rigorous, you need to consider exceptions when using the program)

How to transfer Android data

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.