Activity being fired off too many times
Have another issue here.
Our app starts out with a tab activity. But, before the user can get into the tab activity to do work, we have to check to see if they're logged in. This login is required for all activities within the tab activity. So, instead of having this security check within all the activities, we created our own abstract "activity" and have the tab activities extending our custom activity.
Our "security check" (just see if they have a login key and login token in Preferences) is put within the onResume() of the Abstract activity. If either of these checks come back false, we fire off the login activity and use dialog's within that screen. (We're doing this because we don't want the user to be able to see the data on the tabs if they're not logged in, so this login activity is a black background with dialogs for username/password). The issue is, the onResume() of the abstract activity is being called numerous times, and starts the Login Activity multiple times.
We've tried setting the "singleInstance" and singleTask flags on the xml for the login activi开发者_如何学编程ty, but the activity ends up calling onActivityResult before it is even displayed on the screen.
It seems like your security check is returning false when it shouldn't. With the security check logic you describe, the user will only be prompted with the login activity if the security check returns false. Therefore they shouldn't be prompted multiple times. I would start with your security check and make sure that you are properly checking your login state.
Discovered what was really going on here. When the user started the app in a vertical mode, the app went directly to the Login screen and onResume was only called once, as expected. But if the user started the phone horizontally, the phone would run through a vertical call through onResume, and before the phone would actually start the Login screen, would run through an onResume horizontally. The only way I could think of fixing it was using an static instance count that would be incremented when the activities onCreate and decrement when the onDestroy was called. This instance count was then added to my if statement along with the key and token check to see if one instance was already running.
This solved my problem. Thanks for the suggestions though!
精彩评论