2011-10-12 68 views
0
public void onServiceConnected(ComponentName name, IBinder service) { 
      Log.i("Service connection established",""); 

      // that's how we get the client side of the IPC connection 
      api = com.oreilly.android.otweet.TweetCollectorApi.Stub.asInterface(service); 
      try { 
       api.addListener(collectorListener); 
      /* Intent i = new Intent(StatusListActivity.this, StatusListActivity.class); 
       i.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); 
       startActivity(i);*/ 
      } catch (RemoteException e) { 
       Log.e("", "Failed to add listener", e); 
      } 
+0

你的意思是你想要的应用程序停止时停止服务? – Sandy

+0

是的..也想更新推文 – Payal

回答

0

要停止服务,当应用程序停止时,我们需要在onDestroy()中调用unbindService()

编辑:

在你的链接有代码,这

@Override 
      protected void onDestroy() { 
       super.onDestroy(); 

       try { 
       api.removeListener(collectorListener); 
       unbindService(serviceConnection); 
       } catch (Throwable t) { 
       // catch any issues, typical for destroy routines 
       // even if we failed to destroy something, we need to continue destroying 
       Log.w(TAG, "Failed to unbind from the service", t); 
       } 

       Log.i(TAG, "Activity destroyed"); 
      } 
+0

yaa这是好的..但解除绑定服务是一种方法,所以如何使用它 – Payal

+0

发生了什么桑迪@我等待你的possitive回应plz help..if你可以吗? – Payal

+0

好吧,这是在那里,但它必须打电话 – Payal

相关问题