Problema com Thread e Handler

  • Respostas:1
Gabriel Seiji
  • Posts no fórum: 10

31/07/2015, 04:02:40 via Web

Pessoal,

Alguém consegue me ajudar o por que eu perco o valor ao sair do Handler.
Estou chamando de dentro da Thread o "handler.sendMessage(msg);" e dentro do handleMessage eu atualizo um TextView, porém quando sai do Handler o TextView não está atualizado. A tela até pisca com a atualização, porém perde.
Já tentei criar uma variável com o final String dentro Handler para acessar de fora, porém ela não reconhece.

Segue o código.

thread=new Thread(new MyThread());
thread.start();
handler = new Handler(){
public void handleMessage(Message op) {
String texto = (String)op.obj; //Já tentei criar essa variavel com final, porém não reconhece fora do Handler

editOperadora.setText((String)op.obj);
}
};

contato.setOpTelein(editOperadora.getText().toString());

Log.i("editOperadora", "é: "+editOperadora.getText().toString());
Log.i("OP2", "getTelein: "+contato.getOpTelein());

return contato;
}

class MyThread implements Runnable {
@Override
public void run() {
try {
Message msg = new Message();
msg.obj = "xxx";
handler.sendMessage(msg);
} catch (IllegalStateException e) {
e.printStackTrace();
} /*catch (IOException e) {
e.printStackTrace();
} */
}
}

Responder
Gabriel Seiji
  • Posts no fórum: 10

31/07/2015, 04:04:42 via Web

NÃO SEI SE ISSO AJUDA, MAS É O LOG

07-30 22:52:15.958: E/ACDB-LOADER(188): Error: ACDB AudProc vol returned = -19
07-30 22:52:15.958: D/audio_hw_primary(188): enable_snd_device: snd_device(55: voice-rec-mic)
07-30 22:52:15.963: D/audio_hw_primary(188): enable_audio_route: apply and update mixer path: audio-record
07-30 22:52:16.049: I/HotwordWorker(12145): onReady
07-30 22:52:16.109: W/OpenGLRenderer(1190): Incorrectly called buildLayer on View: lh, destroying layer...
07-30 22:52:16.224: I/PowerManagerService(746): Going to sleep due to power button (uid 1000)...
07-30 22:52:16.224: I/PowerManagerService(746): Sleeping (uid 1000)...
07-30 22:52:16.240: D/PhoneStatusBar(908): disable: < expand ICONS* alerts SYSTEM_INFO* back home recent clock search >
07-30 22:52:16.244: D/BluetoothAdapter(908): 832803335: getState() : mService = null. Returning STATE_OFF
07-30 22:52:16.244: D/BluetoothAdapter(908): 832803335: getState() : mService = null. Returning STATE_OFF
07-30 22:52:16.261: D/BluetoothAdapter(908): 832803335: getState() : mService = null. Returning STATE_OFF
07-30 22:52:16.262: D/BluetoothAdapter(908): 832803335: getState() : mService = null. Returning STATE_OFF
07-30 22:52:16.285: D/audio_hw_primary(188): adev_set_parameters: enter: screen_state=off
07-30 22:52:16.292: E/WifiStateMachine(746): cancelDelayedScan -> 3767
07-30 22:52:16.293: E/native(746): do suspend true

07-30 22:52:16.296: I/Keyboard.Facilitator(1074): onFinishInput()
07-30 22:52:16.311: D/Velvet.SearchPlate(1190): hideKeyboard: false
07-30 22:52:16.316: I/MicrophoneInputStream(12145): mic_close com.google.android.speech.audio.w@187b8c0b
07-30 22:52:16.326: D/Velvet.SearchPlate(1190): setQuery()
07-30 22:52:16.330: D/Velvet.SearchPlate(1190): setExternalFlags(0, null), immediate=false
07-30 22:52:16.330: D/Velvet.SearchPlate(1190): setExternalFlags(0, null), immediate=true
07-30 22:52:16.331: D/Velvet.SearchPlate(1190): updateHintText(showHotwordHint:false, showDiscoveryHint:false)
07-30 22:52:16.372: D/audio_hw_primary(188): disable_audio_route: reset and update mixer path: audio-record
07-30 22:52:16.372: D/audio_hw_primary(188): disable_snd_device: snd_device(55: voice-rec-mic)
07-30 22:52:16.378: I/HotwordRecognitionRnr(12145): Hotword detection finished
07-30 22:52:16.380: I/HotwordRecognitionRnr(12145): Stopping hotword detection.
07-30 22:52:16.401: D/PhoneStatusBar(908): disable: < expand ICONS alerts SYSTEM_INFO back HOME* RECENT* clock SEARCH* >
07-30 22:52:16.519: I/art(746): Explicit concurrent mark sweep GC freed 39963(1908KB) AllocSpace objects, 7(1390KB) LOS objects, 28% free, 40MB/56MB, paused 1.203ms total 85.329ms
07-30 22:52:16.537: D/ScreenOnOffReceiver(29498): Received intent: Intent { act=android.intent.action.SCREEN_OFF flg=0x50000010 }.
07-30 22:52:16.704: D/SurfaceFlinger(180): Set power mode=0, type=0 flinger=0xb6482000
07-30 22:52:16.704: D/qdhwcomposer(180): hwc_blank: Blanking display: 0
07-30 22:52:16.704: I/DisplayManagerService(746): Display device changed: DisplayDeviceInfo{"Tela integrada": uniqueId="local:0", 1080 x 1920, 60.0 fps, supportedRefreshRates [60.0], density 480, 442.451 x 443.345 dpi, appVsyncOff 7500000, presDeadline 12666667, touch INTERNAL, rotation 0, type BUILT_IN, state OFF, FLAG_DEFAULT_DISPLAY, FLAG_ROTATES_WITH_CONTENT, FLAG_SECURE, FLAG_SUPPORTS_PROTECTED_BUFFERS}
07-30 22:52:16.705: V/ActivityManager(746): Display changed displayId=0
07-30 22:52:16.992: D/qdhwcomposer(180): hwc_blank: Done blanking display: 0
07-30 22:52:16.993: D/SurfaceControl(746): Excessive delay in setPowerMode(): 288ms
07-30 22:52:16.993: E/ANDR-PERF-LOCK(2084): Failed to apply optimization for resource: 4 level: 0
07-30 22:52:17.317: W/ResourceType(908): No package identifier when getting value for resource number 0x00000000
07-30 22:52:17.318: W/PackageManager(908): Failure retrieving resources for br.com.mycontacts: Resource ID #0x0
07-30 22:52:20.077: D/Finsky(1839): [165] AppStatesReplicator.handleContentSyncResponse: Completed 0 account content syncs with 0 successful.
07-30 22:52:20.079: D/Finsky(1839): [1] 5.onFinished: Installation state replication succeeded.
07-30 22:52:50.946: W/EventLoggerService(12145): Unable to send logs Error code: 262160 | The connection was not attempted due to lack of network connectivity.
07-30 22:53:16.343: I/Keyboard.Facilitator.LanguageModelFlusher(1074): run()
07-30 22:53:16.343: I/Keyboard.Facilitator(1074): flushDynamicLanguageModels()

Responder