Note that there are some explanatory texts on larger screens.

plurals
  1. POStatic variables not returning correctly?
    text
    copied!<p>I'm building a little app, that's working quite nicely with a service and activity right now. </p> <p>Although, I'm trying to save some static information upon login (like has the service been started already?) into a static boolean, isRunning. It will set to true upon onCreate(), but when I call it later from the activity, it always returns false.</p> <p><strong>From the service:</strong> </p> <pre><code>public static boolean isRunning = false; public void onCreate() { super.onCreate(); isRunning = true; } </code></pre> <p>Does anyone know why this doesn't work? I've tried using some logs to figure out what's happening but I can't seem to figure it out.</p> <p><strong>From the activity</strong></p> <pre><code>public void onResume() { super.onResume(); if(mIsBound) { Log.i(LOG_TAG, "Resuming: Service is running"); if(Service.isRunning) { Log.e(LOG_TAG, "SERVICE IS RUNNING!"); } else { Log.e(LOG_TAG, "SERVICE IS NOT RUNNING!"); } } else { Log.i(LOG_TAG, "Resuming: Service NOT running"); } StopCheck.setChecked(mIsBound); } </code></pre> <p>The mIsBound is what is being created by the activity to bind to the service (I wanted it to rebind, but that seems to be impossible), and it's reliable in its current state. But not outside of that activity, that's what I want to use the static variable for. The Service.isRunning should return true, if mIsBound equals to true. Yet the result of that little test in my log is "Resuming: Service is running" followed by "SERVICE IS NOT RUNNING".</p> <p>Any suggestions or questions are very much appreciated.</p> <p><strong>AS REQUESTED: AndroidManifest.xml</strong></p> <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt; &lt;manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.somnu.ServiceTest" android:versionCode="1" android:versionName="1.0" &gt; &lt;uses-sdk android:minSdkVersion="7" /&gt; &lt;uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" /&gt; &lt;uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" /&gt; &lt;uses-permission android:name="android.permission.INTERNET" /&gt; &lt;application android:icon="@drawable/ic_launcher" android:label="@string/app_name" &gt; &lt;activity android:name=".Login" android:debuggable="true" android:label="@string/app_name" &gt; &lt;intent-filter&gt; &lt;action android:name="android.intent.action.MAIN" /&gt; &lt;category android:name="android.intent.category.LAUNCHER" /&gt; &lt;/intent-filter&gt; &lt;/activity&gt; &lt;activity android:name=".Activity" android:debuggable="true" android:label="@string/app_name" &gt; &lt;/activity&gt; &lt;service android:name=".Service" android:process=":Service" &gt; &lt;/service&gt; &lt;/application&gt; &lt;/manifest&gt; </code></pre>
 

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