Android 来电接收器未取消祝酒

Android 来电接收器未取消祝酒,android,broadcastreceiver,toast,Android,Broadcastreceiver,Toast,我有一个IncomingCallReceiver,它扩展了broadcastReceiver 在onReceive中,我想使用Toast显示一些信息,直到用户接收或拒绝呼叫 当电话铃响时,我正在用循环显示吐司 当用户接到电话或拒绝电话时,我将取消祝酒 但吐司不会被取消 public class IncommingCallReceiver extends BroadcastReceiver { Context context; stat

我有一个
IncomingCallReceiver
,它扩展了
broadcastReceiver

onReceive
中,我想使用Toast显示一些信息,直到用户接收或拒绝呼叫

当电话铃响时,我正在用循环显示吐司

当用户接到电话或拒绝电话时,我将取消祝酒

但吐司不会被取消

 public class IncommingCallReceiver extends BroadcastReceiver
         {

            Context context;
        static Toast toast;

            @Override
        public void onReceive(Context mContext, Intent intent)
         {
        String state = intent.getStringExtra(TelephonyManager.EXTRA_STATE);

        TextView  tv=new TextView(mContext);
        tv.setBackgroundColor(color.background_light);
        Log.i("On Recieve"," ");
        //Toast toast=new Toast(mContext);
        if(state==null)
            return;
        if(state.equals(TelephonyManager.EXTRA_STATE_RINGING))
        {
            for(int i=0;i<7;i++)
            {
               toast=   Toast.makeText(mContext, "Ringing",Toast.LENGTH_LONG);
               toast.show();
            }


        }
         if(state.equals(TelephonyManager.EXTRA_STATE_OFFHOOK))
         {
            // Toast.makeText(mContext, "Recieved", Toast.LENGTH_LONG).show();
             toast.cancel();

         }
        if (state.equals(TelephonyManager.EXTRA_STATE_IDLE))
        {
            //Toast.makeText(mContext, "IDLE", Toast.LENGTH_LONG).show();
             toast.cancel();
        }






    }
 }
公共类IncommingCallReceiver扩展了BroadcastReceiver
{
语境;
静态吐司;
@凌驾
public void onReceive(上下文mContext、意图)
{
字符串状态=intent.getStringExtra(TelephonyManager.EXTRA_状态);
TextView tv=新的TextView(mContext);
电视.背景色(颜色.背景光);
Log.i(“收到时”和“);
//Toast Toast=新的Toast(mContext);
if(state==null)
返回;
if(state.equals(TelephonyManager.EXTRA_state_RINGING))
{

对于(int i=0;i而言,问题在于您正在创建一行中的多个toast-当一个toast完成时,其余的将按顺序显示。您实际上在创建7个不同的toast对象,但只保留对最后一个对象的引用

您需要做的是使用一个Toast;而不是
Toast.LENGTH\u LONG
,使用不同的值。然后您应该能够调用
cancel()