无法使用CustomHashMap扩展主活动

时间:2015-02-27 14:51:02

标签: android

参考:Android:- How to Make dynamic HashMap Accessible in whole application? 我已经设置了一个CustomHashMap(只是3个LinkedHashMaps的集合),这样我就可以从2个Activity中访问它,但我是 无法从SecondActivity访问它!在Manifest.xml中删除红色错误的唯一方法是设置下面的行。如果我 使用 android:name =“com.example.intents.CustomHashMap”(按照在线示例)我收到一条错误消息,说'不是封闭的 class'。

<application
    android:allowBackup="true"
    android:icon="@drawable/ic_launcher_icon"
    android:label="@string/app_name"
    android:theme="@style/CustomActionBarTheme"
    android:name="com.example.intents.MainActivity$CustomHashMap">  //--- The system added the $ parts here.
    <activity
    ....
 protected CustomHashMap thisMap;
 ....
 thisMap = (MainActivity.CustomHashMap)getApplication();

在MainActivity中,我可以执行 thisMap.getKeyValue(4)之类的操作,但是从SecondActivity只返回null。我觉得好像我 在这里缺少一些非常简单有什么想法吗?

1 个答案:

答案 0 :(得分:0)

如此处android:name

为应用程序实现的Application子类的完全限定名称

表示需要传递扩展Application的类名而不是任何其他组件名,例如Activity,Service,...

请参阅以下教程,了解在应用程序中添加Application类:

Global Variable Or Application Context Variable - Android Example

相关问题