即使服务器中没有完成更新,也会发送通知

时间:2017-12-17 17:58:59

标签: android sql-server push-notification

我的问题是代码应该只在我通过每20秒检入服务器添加一个新的商品时发送通知,其中offerNumber>我们已经拥有的优惠号码,当优惠号码变为>我们提供的优惠号码,添加新优惠的通知。 但是,即使没有更新,它也会每20秒发送一次通知。我只需要在offerNumber> offerNum

时发送通知
public class service extends IntentService {

    ResultSet resultSet;
    String offerTitle;
    public static int offerNum = 0;
    String msg="";
    ConnectSQL connectSQL = new ConnectSQL();
    public static boolean ServiceIsRun = false;

    public service() {
        super("MyWebRequestService");
    }

    @Override
    protected void onHandleIntent(@Nullable Intent workintent) {

        while (ServiceIsRun) {
            try {
                resultSet = connectSQL.RunSearch("SELECT * FROM offerdetails where offernumber> " + offerNum + " ", this);

                if (resultSet.next()) {
                    msg= resultSet.getString(1).toString();
                    offerNum = resultSet.getInt(9);
                }

               Intent intent = new Intent();
                //set the action that will receive our broadcast
                intent.setAction("com.example.Broadcast");
                // add data to the bundle
                intent.putExtra("msg", msg);
                // send the data to broadcast
                sendBroadcast(intent);
            } catch (SQLException e) {
                Toast.makeText(getApplication(), e.getMessage(), Toast.LENGTH_LONG).show();
                e.printStackTrace();
            }
            try {
                Thread.sleep(20000);
            } catch (Exception ex) {
            }
        }
    }

}

0 个答案:

没有答案