我有一个在发送短信时调用的接收器。当这种情况发生时,我想举杯。我知道向接收者展示敬酒不是一个好习惯,但我想知道为什么我的代码不起作用
public class SmsSentReceiver extends BroadcastReceiver
{
@Override
public void onReceive(Context context, Intent intent)
{
if (getResultCode() == Activity.RESULT_OK)
Toast.makeText(context, R.string.sent, Toast.LENGTH_SHORT).show();
else
Toast.makeText(context, R.string.error_sending_sms, Toast.LENGTH_LONG).show();
context.unregisterReceiver(this);
}
}
接收器正确接收事件,但没有显示任何 toast。相反,如果我在调试模式下运行应用程序,其中一个 toast 会正确显示。
先感谢您。