1

I have app, in which i am refreshing that app in particular amount of time.

Each time the call is given to webservice and all the messages in database are loaded to listview.

Its done as follows:

public class Messages extends Activity {


    protected Handler handler = new Handler();

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_messages);

        Intent intent = getIntent();

        String message = intent.getStringExtra(MainActivity.EXTRA_MESSAGE);
        String id = intent.getStringExtra(MainActivity.EXTRA_ID);
        String[] lst = null;
        ListView lm=(ListView)findViewById(R.id.listView1);
        TextView tv = (TextView)findViewById(R.id.textView1);

        tv.setText("Welcome " + message);

        handler.postDelayed(new UpdateTask(),750);
    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        // Inflate the menu; this adds items to the action bar if it is present.
        getMenuInflater().inflate(R.menu.messages, menu);
        return true;
    }

    class UpdateTask implements Runnable {

        @Override
        public void run() {
            // TODO Auto-generated method stub

            setContentView(R.layout.activity_messages);

            Intent intent = getIntent();

            String message = intent.getStringExtra(MainActivity.EXTRA_MESSAGE);
            String id = intent.getStringExtra(MainActivity.EXTRA_ID);
            String[] lst = null;
            ListView lm=(ListView)findViewById(R.id.listView1);
            TextView tv = (TextView)findViewById(R.id.textView1);

            tv.setText("Welcome " + message);

            CallSoap cs=new CallSoap();

            lst=cs.GetMessage(id);

            ArrayAdapter<String> adpt = new ArrayAdapter<String>(Messages.this, android.R.layout.simple_list_item_1,lst);

            lm.setAdapter(adpt);

            handler.postDelayed(this, 500);
        }
    }
}

Now, i am just unable to detect (highlight) new messages in my app, because each time when call is given to webservice it retrieves all messages.

How should i detect that this is new message(or can say as data in listview ) for this particular interval of time.

Please help me.

C Sharper
  • 8,284
  • 26
  • 88
  • 151
  • 1
    PrashantAdesara's answer is correct .also,u can go for alarm manager concept /notification manager to notify user with new messages – Ruban Aug 26 '13 at 09:05

1 Answers1

1

Add one field(i.e. Status) in database. And when you call your service and its return all message from database then status need to change with 1 (0 means still webservice not fetch, 1 means its fetch at android side). So after new records inserted your service only fetch the records which status have 0.

I hope this will help you.

PrashantAdesara
  • 1,897
  • 3
  • 22
  • 41