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
A
回答
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");
}
相關問題
- 1. 如何將twitter時間線添加到iphone應用程序?
- 2. 如何使用Android應用程序中的Hashtag過濾twitter主頁時間軸?
- 3. 刷新數據的Android應用程序
- 4. 如何在Twitter應用中嵌入Twitter時間線
- 5. Android中的twitter應用程序如何能夠「近乎」實時更新
- 6. Android應用程序中的Twitter集成
- 7. Twitter應用程序相關的自動刷新功能
- 8. 當應用程序按下按鈕時自動刷新時間線頁面?
- 9. android應用程序中的Twitter應用程序
- 10. 創建Twitter時間的Twitter應用程序
- 11. Twitter的應用程序的Android
- 12. Android的Twitter有時不回到我的Android應用程序
- 13. 如何在執行時間更新Android應用程序
- 14. mvc web應用程序中的應用程序變量刷新
- 15. 如何將Twitter集成到我的Android應用程序中?
- 16. 如何複製Twitter Android應用程序中的彈出框?
- 17. Angular 2實時刷新應用程序
- 18. 如何在Cocoa Mac應用程序的twitter和Facebook中更新
- 19. 線程中的android應用程序類
- 20. 如何增加android應用程序的響應時間?
- 21. Android應用程序的安裝時間?
- 22. 如何刷新或重置phonegap + jquery mobile中的應用程序?
- 23. 如何在Wildfly中「刷新」已部署的應用程序?
- 24. 如何用線程構建Android定時器應用程序?
- 25. 如何刷新Android上的時間,使用dot42 C#
- 26. 如何在使用StartActivityForResult時刷新android應用的UI?
- 27. 如何爲UWP應用程序啓用「應用程序時間線」?
- 28. Twitter流媒體API,如何更新用戶時間線
- 29. 如何在應用程序(活動)仍在運行時刷新?
- 30. 如何在應用程序進入前臺時刷新UIWebView?
你的意思是你想要的應用程序停止時停止服務? – Sandy
是的..也想更新推文 – Payal