編輯:關於Android編程
只是貼代碼,以前寫的突然忘記了.
private WifiManager.MulticastLock multicastLock; public void init(Context context){ WifiManager wifiManager = (WifiManager) context.getSystemService(Context.WIFI_SERVICE); multicastLock = wifiManager.createMulticastLock(my_net); } public byte[] fetchData(){ try { multicastLock.acquire(); MulticastSocket multicastSocket = new MulticastSocket(55551); InetAddress group = InetAddress.getByName(224.0.0.2); multicastSocket.setSoTimeout(3000); multicastSocket.joinGroup(group); multicastSocket.setLoopbackMode(true); byte[] buffer = new byte[512]; DatagramPacket packet = new DatagramPacket(buffer, buffer.length); multicastSocket.receive(packet); return buffer; } catch (Exception e) { e.printStackTrace(); } finally { multicastLock.release();//一定要釋放 } return null; }
來自:https://developer.android.com/guide/components/services.htmlService是一個可以在後台執行長時間運行
在Android開發過程中,經常會碰到Activity之間的切換效果的問題,下面介紹一下如何實現左右滑動的切換效果,首先了解一下Activity切換的實現,從Androi
Android技術精髓-Timing Activity Timing Activity 顧名思義,在activity中實時通過線程通信顯示當前時間,也是主要用到線
比如我們有 2 個分支:master, dev,現在想查看這兩個 branch 的區別,有以下幾種方式:1.查看 dev 有,而 master 中沒有的:git log