Note that there are some explanatory texts on larger screens.

plurals
  1. POAndroid global variable not working in Service
    primarykey
    data
    text
    <p>I'm perplexed why I cannot access my global variables from my service. I can access them from other activities just fine....</p> <p>global var class:</p> <pre><code>public class Global extends Application { private static final String TAG = "Global Class"; int test; public int getTest() { return test; } </code></pre> <p>Main Activity I use this test code:</p> <pre><code>Global appState = ((Global)getApplication()); //Context()); appState.setTest(555); Log.e("SETTEST",new Integer(appState.getTest()).toString()); </code></pre> <p>Result is 555</p> <p>Another activity I use the same code:</p> <pre><code>Global appState = ((Global)getApplication()); //Context()); Log.e("SETTEST",new Integer(appState.getTest()).toString()); </code></pre> <p>Result is 555</p> <p>FInally in my service, I use the same code as above:</p> <pre><code>Global appState = ((Global)getApplication()); //Context()); Log.e("SETTEST",new Integer(appState.getTest()).toString()); </code></pre> <p>and I get big, fat 0 back.</p> <p>Please help. I've spent 3 hours on this so far. I've tried using getApplication, and getApplicationContext</p> <p>Also, manifest looks like this:</p> <pre><code>... &lt;application android:icon="@drawable/signal" android:label="@string/app_ name" android:name="&lt;absolute path&gt;.util.Global"&gt; &lt;service android:name=".util.MyService" android:process=":MyService" android:icon="@drawable/airplane" android:label="@string/service_name" &gt; &lt;/service&gt; </code></pre> <p>**I just tried using a singleton class as well according to this post. same troubles as above:</p> <p><a href="https://stackoverflow.com/questions/8658980/android-global-variables?rq=1">Android - Global variables?</a></p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
 

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