当调用提供给Web服务发现新数据 [英] Detect new data when call is given to webservice
问题描述
我的应用程序,其中我正在刷新的时间特别是量的应用程序。
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.
其完成如下:
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);
}
}
}
现在,我只是无法检测到我的应用程序(高亮)新消息,因为当电话是给web服务它每一次检索的所有邮件。
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.
请帮我。
推荐答案
在数据库中添加一个字段(即状态)。当你打电话给你的服务及其数据库从所有回报消息,则状态需要1更改(0表示还没有WEBSERVICE取,1是指在机器人侧的读取)。所以经过新记录插入您的服务只获取记录其状态有0。
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.
我希望这会帮助你。
这篇关于当调用提供给Web服务发现新数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!