Android Register Broadcast and using it

this is usually set onStart and onStop in activity

onStart you register Receiver

this.registerReceiver(lockBroadcastReceiver, new IntentFilter(BroadCastConstant.LOCK_BROAD_CAST));


onStop you unregister Receiver

this.unregisterReceiver(lockBroadcastReceiver);



and Receiver sample Class
this is just example

private BroadcastReceiver lockBroadcastReceiver = new BroadcastReceiver() {
@Override
public void onReceive(Context context, Intent intent) {

String  initial = intent.getStringExtra("initial");
String  url = intent.getStringExtra("url");

if(initial == null)return;
if(url == null)return;


callAdStatistic(url, initial);
}
};


when you call it you can add parameters

Intent intent = new Intent();
intent.setAction(BroadCastConstant.LOCK_BROAD_CAST);
intent.putExtra("initial", initial);
intent.putExtra("url", url);
sendBroadcast(intent);

Comments

Popular posts from this blog

Project euler 169 found clue

Floyd-Warshall's algorithm