參考來源
https://chris930921.gitbooks.io/android-traveling-gitbook/content/broadcastreceiver/simplemode.html
public class MainActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
final TextView text = new TextView(this);
setContentView(text);
BroadcastReceiver receiver = new BroadcastReceiver() {
@Override
public void onReceive(Context context, Intent intent) {
text.setText("Received Message !");
}
};
final String Action = "FilterStringOne";
IntentFilter filter = new IntentFilter(Action);
registerReceiver(receiver, filter);
new Timer().schedule(new TimerTask() {
@Override
public void run() {
Intent intent = new Intent(Action);
sendBroadcast(intent);
}
}, 2000);
}
}
0 意見:
張貼留言