BroadcastReceiver簡單應用例項

2022-05-07 04:36:07 字數 903 閱讀 3391

broadcastreceiver是android四大元件之一,主要用於接收廣播,它的簡單實現方法如下:
1、定義繼承broadcastreceiver的myreceiver類:
/**

* created by haoye on 2016/3/7. */

public

class myreceiver extends

broadcastreceiver

}

2、在清單檔案中註冊廣播接收器:
<

receiver

android:name

=".myreceiver"

/>

3、用sendbroadcast()函式傳送廣播:
intent intent = new intent(mainactivity.this, myreceiver.class

);intent.setaction("music.play");

sendbroadcast(intent);

4、在onreceive()函式中接收廣播:

修改 onreceive()函式:

@override

public

void

onreceive(context context, intent intent)

}

5.執行測試:

......

ValueListEditor元件應用例項(二)

在上一將的基礎上,接下來就可以編寫button的響應事件了。雙擊 刪除 按鈕進入響應事件的編寫。整個 刪除 按鈕的 如下,水平有限,這裡我就不用仔細解釋了。void fastcall tform2 button1click tobject sender 然後我們再編寫自定義函式update 在上面b...

簡單的Apache URL Rewrite例項

下面開始講如何設定url rewrite.apache 伺服器 比如我們有新聞頁 news readmore.php?id 4875 我們要做成靜態頁 news top2007,4875.html 首先進入apache的目錄找到名為httpd.conf的檔案。本站為 apache2.2 conf h...

python requests,bs4應用例項

import requests from bs4 import beautifulsoup url 1 獲取頁面資訊 response requests.get url content response.text print content 2 分析頁面,獲取id和電影名 soup beautifu...