The application should periodically load JSON from the server. To load JSON, to process it is not a problem. Can not loop.
For example, in activit tried to do this:
protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_master_view); ListView listView = (ListView)findViewById(R.id.list); Downloader downloader = new Downloader(this); SimpleAdapter adapter; while (true){ downloader.execute(); try { listOfElements = downloader.get(); } catch (InterruptedException e) { e.printStackTrace(); } catch (ExecutionException e) { e.printStackTrace(); } adapter = new SimpleAdapter( this, listOfElements, R.layout.list, new String[]{ TITLE, TEXT,}, new int[]{ R.id.title, R.id.text} ); listView.setAdapter(adapter); listView.setChoiceMode(ListView.CHOICE_MODE_SINGLE); try { TimeUnit.MILLISECONDS.sleep(2000); } catch (InterruptedException e) { // TODO Auto-generated catch block e.printStackTrace(); } }
Error IllegalStateExeption takes off: Cannot execute task: the task is already running. I tried to use Thread.sleep () instead of TimeUnit - it also crashes. Where is the mistake?