I create a new thread in which I do a lot of work for about 15 seconds while at the same time, there is a rotating arrow in the center of the screen.
the problem is, the rotate animation is not smooth.
I run a performance test with traceview and get the following graph:
in the above graph, the first row is the main UI thread, and the second row is my own thread, from which you can see at the beginning 4 seconds, my own thread work load is very little and main thread can take almost all the CPU time to do animation rendering, so the animation is fine.
But in the following 1.5s, my thread work load is getting heavy and there are a few white blocks in the main thread which indicates the animation is paused for a little period of time, because CPU is taken away from main thread to my thread to do the heavy work. That's why the animation is not smooth.
I traced the part and found out that BouncyCastleProvider.init took most of the work, and the coresponding code is as follows:
SecretKey k = new SecretKeySpec(key.getBytes(), "AES");
Security.addProvider(new org.bouncycastle.jce.provider.BouncyCastleProvider());
Cipher cipher = Cipher.getInstance("AES/ECB/PKCS7Padding", "BC");
cipher.init(Cipher.ENCRYPT_MODE, k);
finalStr = new String(Base64.encode(cipher.doFinal(originalStr.getBytes())));
But I can't find other way to do AES256Encrypt without using BouncyCastleProvider, and I don't know if there's other way to get a smooth animation, so I hope I can get some ideas from you to optimise the program, thanks!