public class example extends Activity {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
PhoneStateListener myListener = new PhoneStateListener() {
@Override
public void onServiceStateChanged (ServiceState serviceState) {
// Some stuff
}
};
TelephonyManager mTelephonyManager = (TelephonyManager) getSystemService(TELEPHONY_SERVICE);
mTelephonyManager.listen(myListener, PhoneStateListener.LISTEN_SERVICE_STATE);
}
Here is the code. Problem is Listener is getting executed each time the Activity starts rather than only on event listen. Please let me know how can I resolved this issue.