I'm using a ViewPager with four fragments. In every fragment i'm using custom made components that that inheriths from SurfaceView.
If i'm too fast to swipe or change tab when the activity is brought up front the gui freezes. Events etc are still triggered, so the gui-thread is not locked.
I can also see "ghosts" of components sometimes in the view of the intialized components when I swipe.
Does anyone have any idea of what is causing this?
Related
I have been trying to create a tabbed activity for a simple planner application (appropriate files here). I have a RecyclerView inside of a fragment, which is being displayed in a ViewPager that's assigned with the tabs. The issue is, when I use a RecyclerView, the content's don't show and the tabs and action bar scroll up (which can be seen here). I'm using the default and google-supplied code examples, but to no avail. Also, in my fragment with just text, it doesn't seem to center correctly (seen here, is it the size of the fragment?)
Basically, to sum it up, how does one correctly use a RecyclerView in a tabbed activity fragment, and how does one get text to properly center (or get the layout to be the right size) inside of a tabbed activity fragment?
EDIT: The source was hyperlinked (in the "here"s) If you can't find those...
- Gist: https://gist.github.com/Cameronlund4/0e248ea3106d247b52f914affda1885c
- Issue with scrolling: https://imgur.com/a/doi7s
- Issue with centering: https://imgur.com/N767Wg9
More info: I added debug messages to pretty much every method in the adapters, fragments, and activities. All of the GradeFragment's methods are running fine, however the only method being run inside of the ClassAdapter for this is onAttachedToRecyclerView. I'm 99% sure this is the cause of the non-showing up cards (Because the data is never getting put into the cards then), however I have no idea why this would occur.
I have figured out what's going on. In my constructor for the GradeFragment class, I catch an error for a ParseException. Due to my non-android experience, I simply did Exception.printStackTrace() and it never caught my eye as an issue. The thing is, in AndroidStudio, that doesn't show to the default debug window. Learn from my lesson, use log when printing errors.
I'm experimenting with ways to do classical mobile game paradigm: a selector of levels, followed by a game screen.
I fully understand that there are plenty of ways to do that, but i was wondering about what goes wrong when i try this particular one (for learning purposes):
I have an activity, which holds references to my own GLSurfaceView child. On the activity start it loads a default 'level' and perfectly plays it. I can see Render thread started.
I implemented an OptionsMenu item, which after activation inflates a GridView with proper adapter, which allows user to select a level; and sets this inflated Layout to Activity by using setContentView. This is when GLThread dies.
Now i also implemented the OnClick's of that menu so that after click it loads a level in the game engine (works fine, btw) and brings back GLSurfaceView by using setContentView with saved (in 1.) reference.
And that's how i get a blank screen. Everything works fine, menu still works, i can go back to level selector, but in debugger i can see Render Thread doesn't exist.
Please, could someone explain to me what exactly goes wrong here? I'm totally not sure about this OpenGL intrinsic.
I'm working on a multimedia video processing application for Android, and I've run into a bit of a problem. I'm using the FragmentPagerAdapter class with a number of different fragments inside for various steps of video processing.
My first Fragment contains a SurfaceView and a MediaPlayer that feeds it, along with various playback controls. My problem happens when I swipe from fragment 1 (with the SurfaceView) to fragment 2 (empty at the moment). If I haven't yet called start(), nothing unusual happens, and I'm able to swipe between fragments normally. Once I call start() however, the entire screen starts flashing on and off when I swipe to the next Fragment, even if I've put the MediaPlayer in the idle state and it's not feeding frames to SurfaceView. The only thing that stops this is destroying the surface along with the containing view by swiping to the third Fragment so the FragmentPagerAdapter destroys Fragment one, or exiting the application via the home or back button so the view is destroyed.
I can't for the life of me figure out why this is happening, other than that perhaps the SurfaceView rendering thread is somehow interfering with the main UI thread. Nothing unusual appears on LogCat, either, so I'm a bit stuck. I'm running a Galaxy Nexus with android 4.1 as my test hardware.
Any help would be appreciated!
JT
UPDATE: I've managed to find a workaround for now by overriding the setPrimaryItem() method in the FragmentPagerAdapter to call a method that removes the SurfaceView from the hierarchy (using removeView() on its LinearLayout container) when the video player Fragment ceases to be displayed, and then reinstates the SurfaceView when it's active again. There's still a bit of a blink when this happens, unfortunately, so if anyone has additional thoughts, I'd be grateful!
From the Android Developers Blog
This widget[SurfaceView] works by creating a new window placed behind your application’s window. It then punches a hole through your application’s window to reveal the new window.
Because a SurfaceView’s content does not live in the application’s window, it cannot be transformed (moved, scaled, rotated) efficiently. This makes it difficult to use a SurfaceView inside a ListView or a ScrollView.
The Solution is to use a TextureView if you're building for 4.0 or above. If youre interested in using a TextureView to display video this thread might be helpful
I am working on an app , where I am switching between two activities. When control is inside onStart of second activity , there is screen drawing and processing logic being handled.Because of this , when switching between the two activities happens, there is a blank screen that comes up.
Along with this , i also need to render a live video feed in background of my activities/app
What could be the best way to deal with this?
TIA
If you're getting a blank screen it could be because your activity is setting a new contentview but it hasn't been processed properly. Does it ever load completely? If it's just that it's black at the beginning and then renders. Try setting the contentview at the end of your switching in onCreate. This will make it remain on the first activity and avoiding switching views on till everything is loaded.
With regards your second question. Is the live video feed from the Camera?
If it is, set the camera view in the background, make a transparent LinearLayout (or whatever your layout is) over it and then put your various views there.
Your question doesn't have enough specific information to get an accurate idea as to what you're talking about, if my answer doesn't address your problem please respond with elaboration and some code! :-)
Sorry, I know that this topic has been covered a bit. I've read the related posts and am still a bit confused. I am working on an app that while the prototype will have 3 main screens, it will eventually have dozens. Each screen will present either dynmically changing status or take user input. To visualize, it is required to be laid out similar to how MS Word or a typical PC is. It has a status bar at the top and a navigation bar at the bottom that is common to all screens (slight tweaks for some screens, like different icons) in the middle is what I would call a view pane that needs to be updated with a applicable layout.
The status, nav bar, and each screen are defined in their own layout xml file. For my first swag at it I just used a ViewFlipper and loaded the 3 screen layouts into it. However that means that currently I have one main Activity which will not be maintainable as I continue to add screens.
It feels right to me that each screen layout should have an associated Activity class that understands how to control that screen. I need to figure out how to load that into the center pane dynamically. However I thought I read in another post that using multiple Activities can be a CPU and RAM drain.
Currently I tried making one of the screens it's own Activity and kick that off from the main Activity by creating an Intent and than calling startActivity. However that causes the new screen Activity to reside on top of the main Activity. The interesting thing is that then pressing the back button dismissed that activity and returns me to the main.
So far I haven't figured out how to setup having a different Activity control what happens in the center pane.
If I continue down the multiple Activity path, should my main Activity be inheriting from ActivityGroup?
Are using View classes more applicable in this case?
I know this has been a long post. I'd appreciate any advice.
Thanks!
CB
As you noticed, Android will implicitly track a stack of started activities in a task, and the 'back' button ends the top one, reactivating the next one down. I would advise you to think about which kinds of things the user might expect the back button to do, and make it so that activities are separated along those lines.
I haven't played with ActivityGroup so I can't advise you there. If you go with completely separate activities, you can have them all use the same "shell" content view with the common nav/status bar. Have a superclass or utility class handle populating and managing that from there. Then use a a LayoutInflater (you can call getLayoutInflater()) to fill in the middle with your Activity-specific view.
If you want one of the activities to have multiple screens, you might still end up with a ViewFlipper in the center slot. Again, you want to have an Activity transition wherever you want the user to be able to go "back"; that also means you may NOT want to have a change of activities in cases where screens are closely related or part of the same logical thing-being-done. (You can override the back button's behavior, but unless you have a good reason to, it's best to just arrange the app so that Android's basic setup helps your app's UI rather than working at cross purposes.)
If you want to use activities in the fashion you talked about, you might look into using a tab activity. It actually works in the way you want, you just need to hide the tab widget and put your navigation bar there instead. Or, you could go a little deeper and make you own similar tab-like ActivityGroup like Walter mentioned if you have more time.
You could use a view pager with fragments to accomplish the flip between the different views but still allow your activity to have full control over it. The activity can control the menus while the fragment controls your viewing area. This way your back button will properly dismiss the activity containing all pages related to the activity instead of walking down the stack.