gpt4 book ai didi

android - 调用 webservice 时检测新数据

转载 作者:行者123 更新时间:2023-11-30 03:24:42 24 4
gpt4 key购买 nike

我有一个应用程序,我在特定时间内刷新该应用程序。

每次调用 webservice 时,数据库中的所有消息都会加载到 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);
}
}
}

现在,我只是无法在我的应用程序中检测(突出显示)新消息,因为每次调用网络服务时,它都会检索所有消息。

对于这个特定的时间间隔,我应该如何检测到这是新消息(或者可以说是 listview 中的数据)。

请帮帮我。

最佳答案

在数据库中添加一个字段(即状态)。当您调用您的服务并从数据库返回所有消息时,状态需要更改为 1(0 表示仍未获取 web 服务,1 表示它在 android 端获取)。因此,在插入新记录后,您的服务只会获取状态为 0 的记录。

希望对您有所帮助。

关于android - 调用 webservice 时检测新数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18438735/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com