Tuesday, October 30, 2012

what is meant by Stick Intents

Its interview questions i search some sites my knowledge to share to you.

A normal broadcast Intent is not available anymore after is was send and processed by the system. If you use the sendStickyBroadcast(Intent) method, the Intent is sticky, meaning the Intentyou are sending stays around after the broadcast is complete.


// Register for the battery changed event
IntentFilter filter = new IntentFilter(Intent.ACTION_BATTERY_CHANGED);

/ Intent is sticky so using null as receiver works fine
// return value contains the status
Intent batteryStatus = this.registerReceiver(null, filter);

// Are we charging / charged?
int status = batteryStatus.getIntExtra(BatteryManager.EXTRA_STATUS, -1);
boolean isCharging = status == BatteryManager.BATTERY_STATUS_CHARGING
  || status == BatteryManager.BATTERY_STATUS_FULL;

boolean isFull = status == BatteryManager.BATTERY_STATUS_FULL;

// How are we charging?
int chargePlug = batteryStatus.getIntExtra(BatteryManager.EXTRA_PLUGGED, -1);
boolean usbCharge = chargePlug == BatteryManager.BATTERY_PLUGGED_USB;
boolean acCharge = chargePlug == BatteryManager.BATTERY_PLUGGED_AC; 
Sticky Broadcast Intents typically require special permissions.  reference link



first u understand intents and intents filters:

its also nice blog are here:intents and filters


and u study  services also: services





Wednesday, October 24, 2012

convert text to url.


Linkify is used to convert text to link and text to dial phone number also used.

so we used us Linkify.ALL method.


TextView link = (TextView) findViewById(R.id.link);

link.setText("www.google.com");
Linkify.addLinks(link, Linkify.ALL);