6
A
回答
7
這是你可以做什麼:
- 使用ApplicationManager.getForegroundProcessId()
- 使用ApplicationManager.getVisibleApplications()來獲取所有正在運行的應用
- 使用ApplicationManager.getProcessId()搜索應用程序進程的ID
在TimerTask中定義期限
public class AppListenerApp extends Application { int mForegroundProcessId = -1; public AppListenerApp() { Timer timer = new Timer(); timer.schedule(mCheckForeground, 2000, 2000); } public static void main(String[] args) { AppListenerApp app = new AppListenerApp(); app.enterEventDispatcher(); } TimerTask mCheckForeground = new TimerTask() { public void run() { int id = getForegroungProcessID(); if(id != mForegroundProcessId) { mForegroundProcessId = id; String name = getAppNameByProcessId(mForegroundProcessId); showMessage(name); } }; }; private int getForegroungProcessID() { return ApplicationManager.getApplicationManager() .getForegroundProcessId(); } private String getAppNameByProcessId(int id) { String result = null; ApplicationManager appMan = ApplicationManager.getApplicationManager(); ApplicationDescriptor appDes[] = appMan.getVisibleApplications(); for (int i = 0; i < appDes.length; i++) { if (appMan.getProcessId(appDes[i]) == id) { result = appDes[i].getName(); break; } } return result; } private void showMessage(String message) { synchronized (Application.getEventLock()) { Dialog dlg = new Dialog(Dialog.D_OK, message, Dialog.OK, null, Manager.FIELD_HCENTER); Ui.getUiEngine() .pushGlobalScreen(dlg, 1, UiEngine.GLOBAL_QUEUE); } } }
相關問題
- 1. 短信監聽黑莓應用程序和後臺應用程序?
- 2. 超時前景開始,但應用程序轉移到後臺
- 3. 從iOS中的後臺應用程序打開應用程序?
- 4. 前臺iPhone應用程序導致我的後臺應用程序崩潰
- 5. Facebook應用程序進入前臺後
- 6. iphone後臺應用程序
- 7. WinJs後臺應用程序
- 8. 從後臺打開android應用程序
- 9. 從後臺打開iOS應用程序
- 10. BlackBerry - 當執行後臺線程時,應用程序會凍結
- 11. 開源和跨平臺應用程序
- 12. Android和後臺應用程序
- 13. 開始活動不會將應用程序帶到前臺
- 14. 當活動開始時停止應用程序進入前臺
- 15. 開始活動不會將應用程序放在前臺
- 16. 爲鍵盤監聽器部署C#控制檯應用程序
- 17. 用於後臺應用程序的Facebook應用程序認證
- 18. gps應用程序的後臺進程
- 19. 從.NET控制檯應用程序打開.exe應用程序
- 20. 開始播放框架應用程序後退出控制檯
- 21. 開始後臺工作Asp.net 4.0應用程序
- 22. 程序在後臺打開應用程序
- 23. Android:應用程序在後臺或前臺運行? :S
- 24. 如何檢查應用程序是否在前臺或後臺
- 25. 從後臺代理在前臺顯示應用程序
- 26. 如何將ios應用程序從後臺前臺
- 27. 如何從前臺應用程序切換到後臺代理?
- 28. 應用程序從後臺進入前臺
- 29. 在java控制檯應用程序中實現一個關鍵監聽程序
- 30. 在後臺運行BlackBerry PhoneGap應用程序
感謝您的答覆... 相反,那麼這是沒有任何監聽器API或任何類型的事件 ,通過它,我們將獲得當前調用的前臺應用程序。 – 2009-12-28 12:35:01
如果您的應用程序,您可以隨時使用http://www.blackberry.com/developers/docs/4.5.0api/net/rim/device/api/system/Application.html#activate%28%29事件..但在其他情況下,我看不到任何選擇。 – 2009-12-28 15:15:32
好的,謝謝你的回覆 – 2009-12-29 07:15:00