Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>Android provide Application Context that you could subclass and use it in other activities. The steps are (I also highlight the links so you could read up on important things):</p> <ul> <li>Modify your <a href="http://developer.android.com/guide/topics/manifest/manifest-intro.html" rel="nofollow">Android Manifest</a> to include the custom Application. Look at the following section in your AndroidManifest.xml</li> </ul> <pre><code> &lt;application android:icon="@drawable/icon" android:label="@string/app_name" android:theme="@android:style/Theme.NoTitleBar" android:name="com.mypackage.application.MyCustomApplication"&gt; .... </code></pre> <p>The android:name="com.mypackage.application.MyCustomApplication" referring to the class MyCustomApplication which is the subclass of <a href="http://developer.android.com/reference/android/app/Application.html" rel="nofollow">Application</a> that you are going to create</p> <ul> <li>Now, it's time for you to make your subclass. In here you want to make sure you include HashMap&lt;string,String&gt; as part of its variable. So your subclass would look like</li> </ul> <pre><code> public class MyCustomApplication extends Application { HashMap myMap; public MyCustomApplication() { this.myMap = new HashMap(); } public HashMap getMyMap() { return myMap; } } </code></pre> <ul> <li>Once you do that, now you can access your map from any Activity by calling <a href="http://developer.android.com/reference/android/app/Activity.html#getApplication%28%29" rel="nofollow">getApplication()</a>. Make sure you cast the Application to MyCustomApplication to use it properly and get access to the method getMyMap()</li> </ul> <p>Let me know if you need further clarification</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload