Greesogakehor
New Member
I'm now starting to write a service routine and I get an error message everytime I rerun my code without altering anything.Here's the Service routineublic class PollingService extends Service{\[code\]private static final String TAG = PollingService.class.getSimpleName();private Polling updater;public boolean isRunning = false;@Overridepublic IBinder onBind(Intent intent) { return null;}@Overridepublic void onCreate() { super.onCreate(); updater = new Polling(); Log.d(TAG, "On Create'd");}@Overridepublic 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);}@Overridepublic synchronized void onDestroy() { super.onDestroy(); // Stop the Polling updater if(this.isRunning){ updater.interrupt(); } Log.d(TAG, "On Destroy'd");}// Polling Threadclass 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\]}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: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 frontAnd 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.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.Here's the Class I call it fromublic class StartApp extends Activity implements View.OnClickListener{\[code\]TextView disp_hello;Button but_go2send, but_go2request;@Overrideprotected 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\]...}