2011-10-12 69 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

相關問題