@Override public void onCreate() { FLog.init(this, "Service_debug.log"); FLog.i(TAG, "onCreate start."); try { mEngine = Engine.getEngine(); mEngine.init(this); NetworkManager.getInstance().setContext(this); NetworkManager.getInstance().start(); FLog.i(TAG, "NetworkManager.getInstance().start() success."); FacebookChatProxyService.getInstance().setContext(this); FLog.i(TAG, "FacebookChatProxyService.getInstance() success."); IntentFilter filter = new IntentFilter(); filter.addAction(Constants.MAINSERVER_NLSERVICERECEIVER_ACTION); nlservicereciver = new NLServiceReceiver(); registerReceiver(nlservicereciver, filter); new AsyncTask<Void, Void, Integer>() { @Override protected Integer doInBackground(Void... params) { mEngine.start(); return null; } }.execute(); HandlerThread handThread = new HandlerThread("MessageObtain"); handThread.start(); mMessenger = new Messenger(new IncomingHandler(Looper.getMainLooper())); IntentFilter intentFilter = new IntentFilter(); intentFilter.addAction(Constants.ACTION_STOP_SERVICE); intentFilter.addAction(Constants.ACTION_GET_LOG_FROM_SERVICE); registerReceiver(mReceiver, intentFilter); StateManager.getInstance().pushState(new State(State.STATE_DISCONNECTED)); Intent sendIntent = new Intent(); sendIntent.setAction(Constants.NOTIFICATIONDAEMONSERVICE_NLSERVICERECEIVER_ACTION); sendIntent.putExtra(Constants.NOTIFICATION_COMMAND, Constants.COMMAND_SERVICE_STATE); sendBroadcast(sendIntent); } catch (Exception e) { e.printStackTrace(); } FLog.i(TAG, "onCreate finished."); }
@Override public void onDestroy() { FLog.i(TAG, "onDestroy"); NetworkManager.getInstance().stop(); this.unregisterReceiver(mReceiver); unregisterReceiver(nlservicereciver); mEngine.stop(); closeSwClient(); mWSManager = null; StateManager.getInstance().clearState(); }