Note that there are some explanatory texts on larger screens.

plurals
  1. POWhy does Service crash when I rerun program?
    primarykey
    data
    text
    <p>I'm now starting to write a service routine and I get an error message everytime I rerun my code without altering anything.</p> <p>Here's the Service routine:</p> <p>public class PollingService extends Service{</p> <pre><code>private static final String TAG = PollingService.class.getSimpleName(); private Polling updater; public boolean isRunning = false; @Override public IBinder onBind(Intent intent) { return null; } @Override public void onCreate() { super.onCreate(); updater = new Polling(); Log.d(TAG, "On Create'd"); } @Override public int onStartCommand(Intent intent, int flags, int startId) { // Start the Polling updater if(!this.isRunning){ updater.start(); this.isRunning = true; } Log.d(TAG, "On Start'd"); return super.onStartCommand(intent, flags, startId); } @Override public synchronized void onDestroy() { super.onDestroy(); // Stop the Polling updater if(this.isRunning){ updater.interrupt(); } Log.d(TAG, "On Destroy'd"); } // Polling Thread class Polling extends Thread { static final long DELAY = 3000; @Override public void run() { while (isRunning) { try { // Do something Log.d(TAG, "Polling run'ing"); // Sleep Thread.sleep(DELAY); } catch (InterruptedException e) { // Interrupted isRunning = false; } } } } </code></pre> <p>}</p> <p>When I run the app I see in the LogCat "On Create'd" and "On Start'd", and "Polling run'ing", however, I rerun the program to see if I get "On Start'd" only in the LogCat. But instead I get this error:</p> <p>ActivityManager: Starting: Intent { act=android.intent.action.MAIN cat=[android.intent.category.LAUNCHER] cmp=com.project.keegan/.StartApp } ActivityManager: Warning: Activity not started, its current task has been brought to the front</p> <p>And when I check the LogCat it still says, "Polling run'ing". So I went in the emulator: Menu -> App Manager -> and I stopped the Service.</p> <p>When I rerun the program I got the same two errors and my app started but not the service. But here's the funny part, whenever I do any alteration to my code (like if I just pressed the spacebar and then backspace) and clicked Save, and then rerun the program, the Service runs again.</p> <p>Here's the Class I call it from:</p> <p>public class StartApp extends Activity implements View.OnClickListener{</p> <pre><code>TextView disp_hello; Button but_go2send, but_go2request; @Override protected void onCreate(Bundle savedInstanceState) { // TODO Auto-generated method stub super.onCreate(savedInstanceState); setContentView(R.layout.start_app); Vars(); startService(new Intent(this, PollingService.class)); but_go2send.setOnClickListener(this); but_go2request.setOnClickListener(this); } </code></pre> <p>. . . }</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    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