Android Phone state listener
<p>I'm having problem in phone state listener. I want to call one <code>activity</code> from <code>onCallStateChanged</code> event. When i get an incoming call i want to call one <code>activity</code> and process the transaction of the current phone no(which i currently get by incoming call).
But i couldn't go to <code>ShowPhoneStateDialogActivity</code> activity using following code.Please correct me what is my mistake. Thanks in advance.
My code is,</p>

<pre><code> case TelephonyManager.CALL_STATE_RINGING:
                Log.d("PHONE:", "RINGING");
                Log.w("Call STATE:", "RINGING");
                if (!sess.getCallActive()) {
                    sess.setCallActive(true);
                    sess.setActiveMobileNo(incomingCallNumber);
                    this.endActivecall();
                    Intent intent = new Intent(context,ShowPhoneStateDialogActivity.class).setAction("incomingNumber");
                    intent.putExtra("Phoneno", incomingCallNumber);
                    Log.i("CURRENT ACTIVITY",this.getClass().getSimpleName());
                    Log.i("CURRENT CONTEXT","Context:"+context);
                    //intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
                    intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
                    context.startService(intent);
                    break;
                } else {
                    this.endActivecall();
                }
                break;
</code></pre>

<p>And <code>endActivecall</code> function is,</p>

<pre><code>public void endActivecall() {
        TelephonyManager telephony = (TelephonyManager) context
                .getSystemService(Context.TELEPHONY_SERVICE);
        try {
            Class c = Class.forName(telephony.getClass().getName());
            Method m = c.getDeclaredMethod("getITelephony");
            m.setAccessible(true);
            telephonyService = (ITelephony) m.invoke(telephony);
            // telephonyService.silenceRinger();
            telephonyService.endCall();
            Log.i("CALL STATE ACTION:", "Call end");
            Log.i("ACTIVE_MOBILENO:", sess.getActiveMobileNo());
        } catch (Exception e) {
            e.printStackTrace();
        }
</code></pre>
