How to update the Arraylist every second in onNewIntent and in Android 4.3?

I am developing an application where I have to connect to Bluetooth device on Android 4.3. I want to update the Arraylist every second. And in my application. The **DeviceControl.java** will transmit the parameter by using intent and startActivity. The **Main.java** will receive the parameter from **DeviceControl.java** and put in to Arraylist like the dollowing code. **Main.java** public class Main extends Activity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); onNewIntent(getIntent()); } @Override protected void onNewIntent(Intent intent) { // TODO Auto-generated method stub super.onNewIntent(intent); setIntent(intent); for(int i = 0;i<5;i++) { if(address[i].length() != 1) { HashMap item = new HashMap(); item.put("name", name[i]); item.put("address", address[i]); item.put("RSSI", rssi[i]); item.put("Battery", battery[i]); list.add(item); mdeviceAddress = address[i]; } else if(address[i].length() == 1) break; } mHandler.postDelayed(addlist, 1000); //update the list adapter = new SimpleAdapter(this, list, R.layout.device_list_name_address, new String[] {"name", "address", "RSSI", "Battery"}, new int[] {R.id.device_name, R.id.device_address, R.id.device_rssi, R.id.device_battery} ); devicelist.setAdapter(adapter); } But it only update the list once time when the **DeviceControl.java** launch the intent. I want it always update the list after **DeviceControl.java** launch the intent. I have try to type the code of Arraylist in Runnable, but it doesn't work. What should I do to make the Arraylist auto update ?? **EDIT** I add the code of runnable of the following final Runnable addlist = new Runnable() { @Override public void run() { // TODO Auto-generated method stub for(int i = 0;i<5;i++) { if(address[i].length() != 1){ ArrayList> list = new ArrayList>(); HashMap item = new HashMap(); item.put("name", name[i]); item.put("address", address[i]); item.put("RSSI", "11111:" + rssi[i]); item.put("Battery", "22222:" + battery[i]); list.add(item); Log.v(TAG, "onNewIntent----------------------------"); mdeviceAddress = address[i]; Log.v(TAG, "address[" + i + "] = " + address[i]); Log.v(TAG, "GATT[" + i + "] = " + gatt[i]); //並連線到此Address Intent gattServiceIntent = new Intent(Main.this, BluetoothLeService.class); registerReceiver(mGattUpdateReceiver, makeGattUpdateIntentFilter()); bindService(gattServiceIntent, mServiceConnection, BIND_AUTO_CREATE); }else if(address[i].length() == 1) break; } adapter.notifyDataSetChanged(); mHandler.postDelayed(this, 1500); } }; And type the `mHandler.postDelayed(addlist, 1000);` in OnNewIntent after for loop. The list should should be change from item.put("RSSI", rssi[i]); item.put("Battery", battery[i]); to item.put("RSSI", "11111:" + rssi[i]); item.put("Battery", "22222:" + battery[i]); But it didn't change anything.
are you sure that onNewInten is called every second?

以上就是How to update the Arraylist every second in onNewIntent and in Android 4.3?的详细内容,更多请关注web前端其它相关文章!

赞(0) 打赏
未经允许不得转载:web前端首页 » JavaScript 答疑

评论 抢沙发

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址

前端开发相关广告投放 更专业 更精准

联系我们

觉得文章有用就打赏一下文章作者

支付宝扫一扫打赏

微信扫一扫打赏