0

Ref: Android:- How to Make dynamic HashMap Accessible in whole application? I have set up a CustomHashMap (just a collection of 3 LinkedHashMaps) so that I can access it from 2 Activities, but I am unable to access it from the SecondActivity! The only way to remove red errors in Manifest.xml is to set the lines below. If I use android:name="com.example.intents.CustomHashMap" (following the online example) I get an error saying 'is not an enclosing 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();

In MainActivity I can do things like thisMap.getKeyValue(4) but from SecondActivity only null is returned. I feel as if I am missing something very simple here. Any ideas?

Community
  • 1
  • 1
Archdeacon
  • 193
  • 1
  • 4
  • 15
  • Why don't you just make this a static class containing these Hashmaps? Your error is telling you your class is nested inside the First Activity. post this activity please. – kandroidj Feb 27 '15 at 14:54

1 Answers1

0

As see here android:name :

The fully qualified name of an Application subclass implemented for the application

Means need to pass class name which extends Application instead of any other component name like Activity,Service,...

See following tutorial for adding Application class in application :

Global Variable Or Application Context Variable - Android Example

ρяσѕρєя K
  • 132,198
  • 53
  • 198
  • 213
  • All fixed. You are right as I had the CustomHashMap in the wrong class. I made a new Activity (CustomHashMap) and all works as it should. – Archdeacon Feb 27 '15 at 16:23