zoukankan      html  css  js  c++  java
  • Android中利用Application实现多个Activity间共享数据

         在Android中Application只是用来保存应用程序上下文,核心还是在Activity。但我们可以简单的在Application中定义公有的静态变量,从而在多个Activity内调用,实现数据共享。代码如下:

    public class myApp extends Application {
    	
    
    
    	public static HashMap<String, Object> hashMap = new HashMap<String, Object>();
    
    	public static ArrayList<String> strList = new ArrayList<String>();
    	public static ArrayList<Integer> intList = new ArrayList<Integer>();
    	
    }
       利用HashMap<String, Object>可以实现任意数据类型的存储,也可以用ArrayList来存储简单类型。使用时只需要简单的使用myApp.hashMap和myApp.strList等就行了。
    
    
  • 相关阅读:
    LeetCode "Sum Root to Leaf Numbers"
    LeetCode "Single Number"
    POJ #1033
    POJ #1011
    POJ #2411
    POJ #1276
    POJ #1260
    POJ #1221
    POJ #1080
    POJ #1050
  • 原文地址:https://www.cnblogs.com/SSforME/p/3119273.html
Copyright © 2011-2022 走看看