There was a problem with the display of the ProgressBar during the read / write process to the NFC tag. She decided to use AsyncTask, but two more appeared instead) The code itself.
private void CancelAsyncTask(){ mt.cancel(true); } byte[][] bufbuf; class MyTask extends AsyncTask<Ndef, byte[][], Void>{ @Override protected void onPreExecute() { super.onPreExecute(); setVisibilityProgressBar(true); } @Override protected Void doInBackground(Ndef... params) { try { bufbuf = readFromNFC(params[0]); return null; } catch (Exception e){ CancelAsyncTask(); /*mTvMessage.setText("Ошибка чтения. Попробуйте ещё раз."); setVisibilityProgressBar(false);*/ return null; } } @Override protected void onPostExecute(Void result) { super.onPostExecute(result); if(bufbuf != null) { mTvMessage.setText("Успешно"); setVisibilityProgressBar(false); passReadData(bufbuf); } else { mTvMessage.setText("Ошибка чтения. Попробуйте ещё раз."); setVisibilityProgressBar(false); CancelAsyncTask(); } } } When a tag is detected, a new Intent is created in which the following function is called:
public void onNfcDetected(Ndef ndef){ try { mt = new MyTask(); mt.execute(ndef); } catch (Exception e){} } Tag reading function:
@Nullable private byte[][] readFromNFC(Ndef ndef) { try { ndef.connect(); NdefMessage ndefMessage = ndef.getNdefMessage(); if(ndefMessage != null) { byte buf[][] = new byte[ndefMessage.getRecords().length][]; for (int i = 0; i < ndefMessage.getRecords().length; i++) { buf[i] = ndefMessage.getRecords()[i].getPayload(); } Log.d(TAG, "readFromNFC: " + "success"); ndef.close(); return buf; } else{ Log.d(TAG, "readFromNFC: " + "NFC tag null"); //mTvMessage.setText("Ошибка чтения. Попробуйте ещё раз."); return null; } } catch (IOException | FormatException e) { e.printStackTrace(); //mTvMessage.setText("Ошибка чтения. Попробуйте ещё раз."); return null; } } The passReadData function passes the data from the DialogFragment (in which all these functions lie), in activation (so that it is not very interesting to us).
The essence of the program. From the activation, by pressing the button, a fragment is called. When the NFC tag is found, the OnNfcDetected function is launched, the data from the tag is read, transferred to the activation. Activiti starts the second activation and transfers data to it. The second activity processes the data and fills the layout (table). During Debug, the program crashes (but if you go consistently throughout the processing cycle, everything is fine). If you just run the application Run'om, then no problem. If you remove AsyncTask and transfer data in one stream, there are no problems either. Error logs:
05-08 13:07:04.042 25870-25875/com.init_plus.nfc_configurator A/art: art/runtime/jdwp/jdwp_event.cc:681] Check failed: threadId != 0u (threadId=0, 0u=0) 05-08 13:07:04.193 25870-25875/com.init_plus.nfc_configurator A/art: art/runtime/runtime.cc:419] Runtime aborting... art/runtime/runtime.cc:419] Aborting thread: 05-08 13:07:04.194 25870-25875/com.init_plus.nfc_configurator A/art: art/runtime/runtime.cc:419] "Jit thread pool worker thread 0" prio=5 tid=2 WaitingForDebuggerSend (still starting up) art/runtime/runtime.cc:419] | group="" sCount=0 dsCount=0 obj=0x0 self=0xe9247500 art/runtime/runtime.cc:419] | sysTid=25875 nice=9 cgrp=default sched=0/0 handle=0xf3129920 art/runtime/runtime.cc:419] | state=R schedstat=( 0 0 0 ) utm=26 stm=5 core=1 HZ=100 art/runtime/runtime.cc:419] | stack=0xf302b000-0xf302d000 stackSize=1022KB art/runtime/runtime.cc:419] | held mutexes= "abort lock" art/runtime/runtime.cc:419] native: #00 pc 00351e09 /system/lib/libart.so (_ZN3art15DumpNativeStackERNSt3__113basic_ostreamIcNS0_11char_traitsIcEEEEiP12BacktraceMapPKcPNS_9ArtMethodEPv+128) art/runtime/runtime.cc:419] native: #01 pc 00332325 /system/lib/libart.so (_ZNK3art6Thread9DumpStackERNSt3__113basic_ostreamIcNS1_11char_traitsIcEEEEbP12BacktraceMap+304) art/runtime/runtime.cc:419] native: #02 pc 003252d1 /system/lib/libart.so (_ZNK3art10AbortState10DumpThreadERNSt3__113basic_ostreamIcNS1_11char_traitsIcEEEEPNS_6ThreadE+24) art/runtime/runtime.cc:419] native: #03 pc 00325159 /system/lib/libart.so (_ZNK3art10AbortState4DumpERNSt3__113basic_ostreamIcNS1_11char_traitsIcEEEE+424) art/runtime/runtime.cc:419] native: #04 pc 0031bee7 /system/lib/libart.so (_ZN3art7Runtime5AbortEv+90) art/runtime/runtime.cc:419] native: #05 pc 000b4dcb /system/lib/libart.so (_ZN3art10LogMessageD2Ev+866) art/runtime/runtime.cc:419] native: #06 pc 00240135 /system/lib/libart.so (_ZN3art4JDWP9JdwpState19SetWaitForJdwpTokenEy+708) art/runtime/runtime.cc:419] native: #07 pc 0023f981 /system/lib/libart.so (_ZN3art4JDWP9JdwpState24AcquireJdwpTokenForEventEy+76) art/runtime/runtime.cc:419] native: #08 pc 0023f411 /system/lib/libart.so (_ZN3art4JDWP9JdwpState29SendRequestAndPossiblySuspendEPNS0_9ExpandBufENS0_17JdwpSuspendPolicyEy+180) art/runtime/runtime.cc:419] native: #09 pc 002430b1 /system/lib/libart.so (_ZN3art4JDWP9JdwpState16PostClassPrepareEPNS_6mirror5ClassE+1016) art/runtime/runtime.cc:419] native: #10 pc 000e47d1 /system/lib/libart.so (_ZN3art11ClassLinker11DefineClassEPNS_6ThreadEPKcjNS_6HandleINS_6mirror11ClassLoaderEEERKNS_7DexFileERKNS9_8ClassDefE+560) art/runtime/runtime.cc:419] native: #11 pc 000e4431 /system/lib/libart.so (_ZN3art11ClassLinker26FindClassInPathClassLoaderERNS_33ScopedObjectAccessAlreadyRunnableEPNS_6ThreadEPKcjNS_6HandleINS_6mirror11ClassLoaderEEEPPNS8_5ClassE+1016) art/runtime/runtime.cc:419] native: #12 pc 000e500b /system/lib/libart.so (_ZN3art11ClassLinker9FindClassEPNS_6ThreadEPKcNS_6HandleINS_6mirror11ClassLoaderEEE+658) art/runtime/runtime.cc:419] native: #13 pc 000d2685 /system/lib/libart.so (_ZN3art11ClassLinker11ResolveTypeERKNS_7DexFileEtNS_6HandleINS_6mirror8DexCacheEEENS4_INS5_11ClassLoaderEEE+132) art/runtime/runtime.cc:419] native: #14 pc 00134625 /system/lib/libart-compiler.so (_ZNK3art19HInstructionBuilder25IsOutermostCompilingClassEt+528) art/runtime/runtime.cc:419] native: #15 pc 00133fc3 /system/lib/libart-compiler.so (_ZN3art19HInstructionBuilder16BuildNewInstanceEtj+626) art/runtime/runtime.cc:419] native: #16 pc 0012f11b /system/lib/libart-compiler.so (_ZN3art19HInstructionBuilder21ProcessDexInstructionERKNS_11InstructionEj+3522) art/runtime/runtime.cc:419] native: #17 pc 0012de1d /system/lib/libart-compiler.so (_ZN3art19HInstructionBuilder5BuildEv+1176) art/runtime/runtime.cc:419] native: #18 pc 00112c3d /system/lib/libart-compiler.so (_ZN3art13HGraphBuilder10BuildGraphEv+84) art/runtime/runtime.cc:419] native: #19 pc 001571c9 /system/lib/libart-compiler.so (_ZNK3art18OptimizingCompiler10TryCompileEPNS_14ArenaAllocatorEPNS_19CodeVectorAllocatorEPKNS_7DexFile8CodeItemEjNS_10InvokeTypeEtjP8_jobjectRKS5_NS_6HandleINS_6mirror8DexCacheEEEPNS_9ArtMethodEb+2452) art/runtime/runtime.cc:419] native: #20 pc 00158e03 /system/lib/libart-compiler.so (_ZN3art18OptimizingCompiler10JitCompileEPNS_6ThreadEPNS_3jit12JitCodeCacheEPNS_9ArtMethodEb+330) art/runtime/runtime.cc:419] native: #21 pc 00107ebf /system/lib/libart-compiler.so (_ZN3art3jit11JitCompiler13CompileMethodEPNS_6ThreadEPNS_9ArtMethodEb+194) art/runtime/runtime.cc:419] native: #22 pc 002505c3 /system/lib/libart.so (_ZN3art3jit3Jit13CompileMethodEPNS_9ArtMethodEPNS_6ThreadEb+318) art/runtime/runtime.cc:419] native: #23 pc 00251ce7 /system/lib/libart.so (_ZN3art3jit14JitCompileTask3RunEPNS_6ThreadE+430) art/runtime/runtime.cc:419] native: #24 pc 003451e9 /system/lib/libart.so (_ZN3art16ThreadPoolWorker3RunEv+44) art/runtime/runtime.cc:419] native: #25 pc 00344d21 /system/lib/libart.so (_ZN3art16ThreadPoolWorker8CallbackEPv+64) art/runtime/runtime.cc:419] native: #26 pc 00047f93 /system/lib/libc.so (_ZL15__pthread_startPv+22) art/runtime/runtime.cc:419] native: #27 pc 0001a161 /system/lib/libc.so (__start_thread+6) art/runtime/runtime.cc:419] (no managed stack frames) art/runtime/runtime.cc:419] Dumping all threads without appropriate locks held: thread list lock mutator lock art/runtime/runtime.cc:419] All threads: art/runtime/runtime.cc:419] DALVIK THREADS (16): art/runtime/runtime.cc:419] "main" prio=5 tid=1 Runnable art/runtime/runtime.cc:419] | group="" sCount=0 dsCount=0 obj=0x75922698 self=0xf3a05400 art/runtime/runtime.cc:419] | sysTid=25870 nice=0 cgrp=default sched=0/0 handle=0xf6c3e534 art/runtime/runtime.cc:419] | state=R schedstat=( 0 0 0 ) utm=84 stm=13 core=2 HZ=100 art/runtime/runtime.cc:419] | stack=0xff7dc000-0xff7de000 stackSize=8MB art/runtime/runtime.cc:419] | held mutexes= "mutator lock"(shared held) art/runtime/runtime.cc:419] native: #00 pc 00351e09 /system/lib/libart.so (_ZN3art15DumpNativeStackERNSt3__113basic_ostreamIcNS0_11char_traitsIcEEEEiP12BacktraceMapPKcPNS_9ArtMethodEPv+128) art/runtime/runtime.cc:419] native: #01 pc 00332325 /system/lib/libart.so (_ZNK3art6Thread9DumpStackERNSt3__113basic_ostreamIcNS1_11char_traitsIcEEEEbP12BacktraceMap+304) art/runtime/runtime.cc:419] native: #02 pc 00344477 /system/lib/libart.so (_ZN3art14DumpCheckpoint3RunEPNS_6ThreadE+622) art/runtime/runtime.cc:419] native: #03 pc 00332eb5 /system/lib/libart.so (_ZN3art6Thread21RunCheckpointFunctionEv+144) art/runtime/runtime.cc:419] native: #04 pc 003f614d /system/lib/libart.so (_ZN3artL12GoToRunnableEPNS_6ThreadE+52) art/runtime/runtime.cc:419] native: #05 pc 003f60ef /system/lib/libart.so (_ZN3art12JniMethodEndEjPNS_6ThreadE+8) art/runtime/runtime.cc:419] native: #06 pc 002df629 /system/framework/arm/boot-framework.oat (Java_android_content_res_AssetManager_applyStyle__JIIJ_3I_3I_3I+212) art/runtime/runtime.cc:419] at android.content.res.AssetManager.applyStyle!(Native method) art/runtime/runtime.cc:419] at android.content.res.ResourcesImpl$ThemeImpl.obtainStyledAttributes(ResourcesImpl.java:1189) art/runtime/runtime.cc:419] - locked <0x064435de> (a android.content.res.Resources$ThemeKey) art/runtime/runtime.cc:419] at android.content.res.Resources$Theme.obtainStyledAttributes(Resources.java:2364) art/runtime/runtime.cc:419] at android.content.Context.obtainStyledAttributes(Context.java:612) art/runtime/runtime.cc:419] at android.view.View.<init>(View.java:4475) art/runtime/runtime.cc:419] at android.widget.TextView.<init>(TextView.java:1025) art/runtime/runtime.cc:419] at android.widget.TextView.<init>(TextView.java:1019) art/runtime/runtime.cc:419] at android.widget.TextView.<init>(TextView.java:1015) art/runtime/runtime.cc:419] at android.widget.TextView.<init>(TextView.java:1011) art/runtime/runtime.cc:419] at com.init_plus.nfc_configurator.Tabs.createSeek(Tabs.java:1626) art/runtime/runtime.cc:419] at com.init_plus.nfc_configurator.Tabs.Fill_table(Tabs.java:1204) art/runtime/runtime.cc:419] at com.init_plus.nfc_configurator.Tabs.PageNameArray(Tabs.java:1155) art/runtime/runtime.cc:419] at com.init_plus.nfc_configurator.Tabs.onCreate(Tabs.java:298) art/runtime/runtime.cc:419] at android.app.Activity.performCreate(Activity.java:6955) Not all, for so footwoman turned out. Where to look here to identify a scoundrel who paints everything? Due to inexperience, I can’t even imagine what to look at and where the problem is.
I hope for your help.