To preface this question, this is my first app and I have a very basic understanding of android apps.
My first problem is the issue with screen orientation change. I've seen this question asked on here a million times, but I don't really understand the answers and I'm not sure if it is the same situation or not. My app crashes when the screen orientation changes. I am not using ViewFlipper as a lot of the questions mention. My app also crashes when you try to scroll through the options in a spinner. The spinner is populated correctly, and you can open it and select an option, but scrolling or opening it and changing selection multiple times causes a crash. I think my biggest problem here is I am not used to the Eclipse IDE or java (I am a .net developer primarily) and I feel like it leaves me completely in the dark when it crashes. All it ever says is "Source not found". That doesn't help me much.
So I guess my question is: does anyone know what would cause the application to crash in either of these two instances and/or how do I go about debugging the issues when it simply says "source not found"?
I figured out the issues. Sort of anyways.
The spinner crash was caused by a null value in the array I was binding as the source. So that one was my fault.
The orientation crash was caused by... I'm not really sure. But to investigate I inserted android:configChanges="orientation" into the manifest to be able to handle the onConfigurationChanged event. I inserted the code to override the method and the problem stopped completely.
#Override
public void onConfigurationChanged(Configuration newConfig) {
super.onConfigurationChanged(newConfig);
}
That is the code necessary to fix the problem in it's entirety. I have no idea what was causing the problem or why that fixed it so if anyone can shed some light please comment!
Related
I noticed something strange after implementing and testing a settings screen for my TV app using the LeanbackSettingsFragmentCompat class, please see attached image:
As you can see, after navigating with the remote to other items, the items no longer in focus still retain their focused background state, I was only able to reproduce this behaviour on one device, and it rarely happens
This problem has left me a bit perplexed,as this is not my implementation but rather Leanback's.. But still, I have never seen a TV app with this problem
Has anyone ever encountered such an issue? Could I have made a mistake to cause something like that?
I would be happy to share code, but at this point I don't know if my code is even relevant to this problem
Thanks in advance
This problem happen after android studio suddenly close itself. I feel relieve when i see the interface output can show it's text but, it annoy me when i try to codes the interface and there is no text shown there. How can i solve this problem and what make this problem occur?
I already solve this problem by use the new render layout. I kind a hesitate to use it at first because i have face this problem before and it is also render problem. No matter how many time i change my codes according to suggestion and change the render layout. Still nothing works. I need start from scratch because i can't find the solution. But this time it's work.
I'm having a weird bug that I'm not sure how to debug. I have have an activity set up to show movie trailers and reviews. Everything looks and works fine when the app is initially started unless I navigate away from the app to another app or youtube to watch the trailer. Then when I come back into my app the trailer names and reviews are all out of the original order and just messed up (some are duplicated). However when I click on the the trailer name (that is now incorrect) it takes me to the correct trailer! Also when I come back to the app if I try rotating the phone sideways it won't rotate. Rotation and everything else works perfectly fine before I navigate away from the app and come back. I'm so confused. I've tried different onSaveInstanceState etc. implementations but nothing is working. I don't even know what code snippet to post since I don't know where the error could possibly be occurring.
Yup as David Wasser wrote above the issue was with my adapter and nothing to do with onSaveInstanceState. I was assigning the textview in the incorrect method of the adapter (I was assigning it where I defined my viewholder and not on the onBind method) so it wasn't being handled properly.
I am experiencing a rather subtle and undetectable bug in one of my Android app's activities. Under certain conditions, when I transition the activity from landscape to portrait, or vice-versa, the app crashes. What is particularly difficult and annoying about this bug is that none of the breakpoints in the activity are being hit in debug mode when I do the transition. In addition, logcat does not seem to be much help, and nothing shows up there either.
So I would be looking for some suggestions about what could cause a crash on orientation change. I can post some code, but I obviously can't post everything, and I'm not sure how much help it would be to post a few fragments from the activity.
The lifecycle of an Activity is such that on orientation change events like onCreate() and onStop() (for example) are not called. So, if you have created objects in onCreate() they might not be initialized (=null) when your Activity returns after being rotated. Check your code for objects that might be initialized in onCreate().
Also you might want to add a few more try..catch with Log.e messages.
To be honest, if your app crashes, there should be an error logged in the logcat.
I was on the verge of giving up, when something turned up in Logcat after one of the failed tests:
java.lang.NullPointerException: Attempt to invoke virtual method 'void
com.google.android.gms.maps.model.Marker.setIcon
(com.google.android.gms.maps.model.BitmapDescriptor)' on a null object reference
I followed the stack trace to the point in the activity where the null pointer exception happened. In fact, as many of you suggested in comments, there was some state which was not being restored properly. The exact problem was happening in the initialization of a Google Map.
At first glance now, this question seems to be of the "why isn't this code working" type. However, it is not, because both debugging and, most of the time, Logcat, failed to reveal what the problem was.
As a take home message, if you ever encounter bugs in your Android code, you should not rely on debugging alone, because it might not work. Logcat seems to have come through here, but even it seemed to not be reproducible every time.
I have a serious problem with my App continously crashing on some users devices with the following exception in an Activity onStart method:
Caused by: java.lang.IllegalStateException: Can not perform this action after onSaveInstanceState
at android.support.v4.app.FragmentManagerImpl.checkStateLoss(FragmentManager.java:1299)
at android.support.v4.app.FragmentManagerImpl.enqueueAction(FragmentManager.java:1310)
at android.support.v4.app.BackStackRecord.commitInternal(BackStackRecord.java:541)
at android.support.v4.app.BackStackRecord.commit(BackStackRecord.java:525)
at android.support.v4.app.DialogFragment.show(DialogFragment.java:123)
I cannot reproduce this error locally in my emulator. I have found a few questions regarding this issue on stackoverflow:
here and
here
I have tried the suggested solution, i.e. do not allow empty bundles in onSaveInstance neither in fragments nor activities.
However the problem remains. This is the only Crash report I ever get, and I get it continously.
Does anyone have a working solution?
I have solved this issue by
upgrading my support lib to revision 10
using workaround posted here: http://code.google.com/p/android/issues/detail?id=23096
i.e.. Add a non-ui fragment in onResumeFragments and invoke further transactions in Listener Callback.
Check my answer here for code: "Can not perform this action after onSaveInstanceState" - why am I getting this exception from my activity's onResume method?
Got no more IllegalStateException so far.
I solved this using this workaround, namely put the code into a methods onPostResume() function in the Activity
Read This Article.
And,
This one.
Once the issue is understood, go ahead and change things properly:
Figure out why your transactions are happening outside your onResume state. Why are these things happening when they shouldn't be. Why are you manually adding and removing fragments with regard to the lifecycle of you app rather than when the user requests. You should maybe need one time in the onCreate() or when the user invokes something. But why are you messing with them in onResume() in the first place? Don't do that.
If you change all the .commit() to .commitAllowStateLoss() then the crashes will go away. But, you're better off not doing that. You are better off making sure you never change your fragments except when the app is fully live. Sometimes that means never loading a fragment from the OnActivityResult() but rather flagging to run in your onPostResume(), and avoiding performing UI changes in async threads that wrongly assume you couldn't have killed the activity in the meantime.
If you just want to spackle everything, .commitAllowStateLoss() will do that. If you want to do it right, make sure you don't fiddle with your fragments after things die.
One of the more recent forms of Android circa Oreo I think, changed this to avoid this annoying error. My answer seems a bit vague but it's because the bug is in the paradigm. You entirely can hit that with various code elements and fairly routinely.