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