마스터Q&A 안드로이드는 안드로이드 개발자들의 질문과 답변을 위한 지식 커뮤니티 사이트입니다. 안드로이드펍에서 운영하고 있습니다. [사용법, 운영진]

1초 간격으로 Thread를 실행하고 싶어요

0 추천

https://github.com/NordicPlayground/Android-nRF-UART

해당 소스를 보며 BLE 통신을 공부하고 있습니다.

listView로 값들을 읽어오는데, 거의 0.01초 간격으로 값들이 갱신됩니다.

1초나 5초 간격으로 값을 확인하고 싶은데, delay를 넣으면 실행이 안되어요..ㅠ

어떻게 해야할까요..ㅠㅠ

 

private final BroadcastReceiver UARTStatusChangeReceiver = new BroadcastReceiver() {

        public void onReceive(Context context, Intent intent) {
            String action = intent.getAction();

            final Intent mIntent = intent;
           //*********************//
            if (action.equals(UartService.ACTION_GATT_CONNECTED)) {
            	 runOnUiThread(new Runnable() {
                     public void run() {
                         	String currentDateTimeString = DateFormat.getTimeInstance().format(new Date());
                             Log.d(TAG, "UART_CONNECT_MSG");
                             btnConnectDisconnect.setText("Disconnect");

                             ((TextView) findViewById(R.id.deviceName)).setText(mDevice.getName());
                            Toast.makeText(getApplicationContext(), "Connected to: "+ mDevice.getName(), Toast.LENGTH_LONG).show();
                            mState = UART_PROFILE_CONNECTED;
                     }
            	 });
            }

          //*********************//
            if (action.equals(UartService.ACTION_GATT_DISCONNECTED)) {
            	 runOnUiThread(new Runnable() {
                     public void run() {
                    	 	 String currentDateTimeString = DateFormat.getTimeInstance().format(new Date());
                             Log.d(TAG, "UART_DISCONNECT_MSG");
                             btnConnectDisconnect.setText("Connect");

                             ((TextView) findViewById(R.id.deviceName)).setText("Not Connected");
                             Toast.makeText(getApplicationContext(), "Disconnected to: "+ mDevice.getName(), Toast.LENGTH_LONG).show();
                             mState = UART_PROFILE_DISCONNECTED;
                             mService.close();

                     }
                 });
            }


          //*********************//
            if (action.equals(UartService.ACTION_GATT_SERVICES_DISCOVERED)) {
             	 mService.enableTXNotification();
            }
          //*********************//
            if (action.equals(UartService.ACTION_DATA_AVAILABLE)) {

                 final byte[] txValue = intent.getByteArrayExtra(UartService.EXTRA_DATA);
                 runOnUiThread(new Runnable() {
                     public void run() {
                         try {

                             String text = new BigInteger(1, txValue).toString(16);
                             String currentDateTimeString = DateFormat.getTimeInstance().format(new Date());

                             listAdapter.add("["+currentDateTimeString+"] RX: "+text);
                             messageListView.smoothScrollToPosition(listAdapter.getCount() - 1);
                         } catch (Exception e) {
                             Log.e(TAG, e.toString());
                         }
                     }
                 });
             }


           //*********************//
            if (action.equals(UartService.DEVICE_DOES_NOT_SUPPORT_UART)){
            	showMessage("Device doesn't support UART. Disconnecting");
            	mService.disconnect();
            }


        }
    };

 

도와줘 님이 2020년 2월 11일 질문

4개의 답변

0 추천

100% 정확한 시간에 wakeup 하는건 불가능합니다만.

이 경우 countdowntimer를  쓰시는게 깔끔할 듯 합니다.

https://iw90.tistory.com/127

익명사용자 님이 2020년 2월 11일 답변
0 추천
1초 반복 실행은 다양한 방법이 있습니다만

대표적인 방법은 TimerTask입니다.
디자이너정 (42,810 포인트) 님이 2020년 2월 11일 답변
0 추천
Propecia Galenico  [url=https://cheapcialisir.com/#]when will cialis go generic[/url] Triamterene Hctz 375 25 Mg  <a href=https://cheapcialisir.com/#>Cialis</a> Mail Order Finasteride Mastercard
DenAttand 님이 2020년 4월 22일 답변
0 추천
Thread.sleep(1000); 1초마다

Thread.sleep(5000); 5초마다
용서해라사스케 (480 포인트) 님이 2020년 4월 26일 답변
...