Today, I found my program has different unknown error in emulator and my phone. Because I don’t have any idea about it, so can anyone give me some hints?
In my program, it exist the following code:
requestWindowFeature(Window.FEATURE_NO_TITLE);
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,WindowManager.LayoutParams.FLAG_FULLSCREEN);
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
Case 1: The program is running in emulator
It can run normally, until I changed the screen orientation. I had to debug. I found that it throw error because some value changed to null after orientation.
following is the logcat:
04-25 22:04:35.378: W/dalvikvm(520): threadid=23: thread exiting with uncaught exception (group=0x4001aa28)
04-25 22:04:35.378: E/AndroidRuntime(520): Uncaught handler: thread Thread-15 exiting due to uncaught exception
04-25 22:04:35.388: E/AndroidRuntime(520): java.lang.NullPointerException
04-25 22:04:35.388: E/AndroidRuntime(520): at com.mytest.testit.Maincore.logicGo(Maincore.java:244)
04-25 22:04:35.388: E/AndroidRuntime(520): at com.mytest.testit.Maincore.run(Maincore.java:325)
04-25 22:04:35.388: E/AndroidRuntime(520): at java.lang.Thread.run(Thread.java:1060)
04-25 22:04:35.398: I/dalvikvm(520): threadid=7: reacting to signal 3
04-25 22:04:35.418: I/dalvikvm(520): Wrote stack trace to '/data/anr/traces.txt'
Case 2: The program is running in my phone
It can run normally even though I rotate my phone. But if I lock and unlock the phone, the program will throw error. About this error, I don’t know how to trace. It is because this problem will not appear at the emulator.
Can anyone give some hints for me?
When you rotate the device, the activity is re-created. Any data you want to save, you need to do so in onSaveInstanceState();
There is a good answer about it here