Android:Toast类型中的方法makeText(Context,CharSequence,int)不适用于参数(MyBroadCastReceiver,String,int)

时间:2012-10-02 02:19:30

标签: android toast

我无法弄清楚错误,请帮助这是代码。我一直得到“Toast类型中的方法makeText(Context,CharSequence,int)不适用于参数(MyBroadCastReceiver,String,int)”

    public class MyBroadCastReceiver extends BroadCastReceiver {

public void onReceive(Context context, Intent alarmIntent) {
    // TODO Auto-generated method stub

    Toast.makeText(MyBroadCastReceiver.this, "Alarm worked", Toast.LENGTH_LONG).show();
}

}

3 个答案:

答案 0 :(得分:5)

应该是

Toast.makeText(context, "Alarm worked", Toast.LENGTH_LONG).show();

答案 1 :(得分:3)

尝试使用makeText(context,...)。

答案 2 :(得分:0)

您必须将活动作为上下文传递。 尝试

Toast.makeText(MyBroadCastReceiver.this.getActivity(),“Alarm working”,Toast.LENGTH_LONG).show();