Friday, December 21, 2012

[android-developers] Re: Toast in phone state listener

It's because you are creating a new toast object and canceling the new object rather than the old object that's showing.


Maybe make the toast a member variable?



On Friday, December 21, 2012 1:04:09 AM UTC-6, sujit dubey wrote:
 
    I am trying to display a toast on incoming call and the toast should disappear on "CALL_STATE_IDLE" but toast continues to appear even after reaching to idle state,
     here is my code:

        @Override
    public void onCallStateChanged(int state, String incomingNumber) {

          Toast toast = new Toast(ctx); // i am passing context here
          switch(state){
        case TelephonyManager.CALL_STATE_IDLE:
            Log.d("DEBUG", "IDLE");

          toast.cancel();
           
            break;

        case TelephonyManager.CALL_STATE_OFFHOOK:
            Log.d("DEBUG", "OFFHOOK");
         
            break;
        case TelephonyManager.CALL_STATE_RINGING:
             
            Log.d("DEBUG", "RINGING");
          toast.makeText( ctx, "incoming call " , Toast.LENGTH_SHORT).show();
           
            break;
        }
    }

--
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscribe@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

0 Comments:

Post a Comment

Subscribe to Post Comments [Atom]

<< Home


Real Estate