Hello. My question is the following: There is a SimpleAdapter in which messages from the server are loaded. In the adapter, the method ( Parcelable state = sList.onSaveInstanceState(); и sList.onRestoreInstanceState(state); ) I save the current position of the scroll, as the adapter updates the data every 5 seconds. Those. My adapter is constantly being recreated, but I do not need this. I want to do this ... Json'om every 5 seconds to check for the presence of a new message, and if it is, then pull out this message and add it to an existing adapter. As I understand it, you need to create a separate class AsyncTask, which will send requests every 5 seconds. Did, pulled the data (written in the logs) ... but how to add them to an existing adapter now?
I update the handler data, in the FriendMsgLoad () method, AsynkTask itself is sending a request via HttpURLConnection.
class RefreshActivity extends Thread { @Override public void run() { runOnUiThread(new Runnable() { @Override public void run() { mHandler.postDelayed(this, 5000); FriendMsgLoad friendMsgLoad = new FriendMsgLoad(); friendMsgLoad.execute(); } }); } }
List<>) that you use for the adapter and call the adapternotifyDataSetChanged(). At the same time you do not need to recreate the adapter - Vladyslav Matviienkodata = new ArrayList<Map<String, Object>>();I add the data, I drive it to the map, but as soon as I callnotifyDataSetChanged, the error NullPointerException is received - sergei1094String[] from = {LV_MSGID, LV_MSG, LV_USID_MSG, LV_MSG_TIME}; int[] to = {R.id.id_msg, R.id.msg, R.id.id_msg_user, R.id.msg_time}; new FriendMsgActivity().dataChanged(data, from, to);After a network request, I pass thedatato thedataChangedmethod and try to assign values to the adapter already inside theFriendMsgActivityclass.java.lang.IllegalStateException: System services not available to Activities before onCreate()I get an errorjava.lang.IllegalStateException: System services not available to Activities before onCreate()- sergei1094