1

我无法弄清楚错误,请帮助这是代码。我不断收到“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();
}

}

4

3 回答 3

5

应该

Toast.makeText(context, "Alarm worked", Toast.LENGTH_LONG).show();
于 2012-10-02T02:21:29.787 回答
3

尝试 makeText(context, ...) 代替。

于 2012-10-02T02:20:58.803 回答
0

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

Toast.makeText(MyBroadCastReceiver.this.getActivity(),"报警工作", Toast.LENGTH_LONG).show();

于 2016-07-07T05:16:55.613 回答