Back to project page AndroidText.
The source code is released under:
Apache License
If you think the Android project AndroidText listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.
package com.jiechic.androidtext._1_daemon; /*from ww w .j a va2s . c om*/ import android.app.Service; import android.content.Intent; import android.os.IBinder; /** * Created by jiechic on 14-10-15. */ public class _1_Service1 extends Service{ private checkThread mThread; @Override public IBinder onBind(Intent intent) { return null; } @Override public int onStartCommand(Intent intent, int flags, int startId) { startDaemon(); return super.onStartCommand(intent, flags, startId); } private void startDaemon() { if (mThread == null || !mThread.isAlive()) { mThread = new checkThread(); mThread.start(); } } @Override public void onDestroy() { mThread.stopRun(); mThread=null; System.gc(); super.onDestroy(); } class checkThread extends Thread{ private Boolean isRun=true; @Override public void run() { super.run(); while (isRun){ if (!Util.isServiceAlive(_1_Service1.this, _1_Service2.class)) { startService(new Intent(_1_Service1.this,_1_Service2.class)); } try { Thread.sleep(2000); } catch (InterruptedException e) { e.printStackTrace(); } } } public void stopRun(){ isRun=false; } } }