Click here to Skip to main content
15,606,617 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
My problem is that the code should send notification only when i add a new offer by checking in the server every 20seconds where offerNumber > the offer number we already have and when offer number become > offer number that we have, it sends notification with new offer added. But, it sends notification every 20 seconds even if there is no update .. I need to send notification only when offerNumber>offerNum

What I have tried:

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() {

protected void onHandleIntent(@Nullable Intent workintent) {

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

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

           Intent intent = new Intent();
            //set the action that will receive our broadcast
            // add data to the bundle
            intent.putExtra("msg", msg);
            // send the data to broadcast
        } catch (SQLException e) {
            Toast.makeText(getApplication(), e.getMessage(), Toast.LENGTH_LONG).show();
        try {
        } catch (Exception ex) {
Updated 19-Dec-17 8:05am
David Crow 19-Dec-17 10:17am    
How about not calling sendBroadcast() if resultSet is empty?

1 solution

As mentioned in the comments, if you want to do a check before calling a function use the if statement.
Share this answer

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900