Android tab missing children after app sits - android

I have created an app that gets a list from a website and stores it in the cache. These values are then displayed in a tab. Each value gets put into a TextView that is created when the Fragment is created. That part works perfectly fine, even when I don't have an internet connection (so it is relying on what was stored in the cache).
I have found that if I let the app sit for a while, just using my phone as normal, when I go back into the app that tab is blank. I'm not really sure what the problem is since I don't get any error messages. If I go to the app chooser and swipe the app closed, the next time I run the app it goes back to the splash page and everything works great. Am I missing something to be able to have a view that I created programatically be able to be stored in memory?

You will have to explicitely save the contents of your TextViews, and in general any view that you wish its contents to remain after an onPause of your activity. Specifically for TextViews you can do that in your xml definition by adding
android:freezesText="true"
If you add your TextView programmatically, you can try this:
textView.setFreezesText(true);

Related

When I minimize my application and reopen it, resize the layout

Hello the problem is that when minimizing and reopening when pressing any textview, the layout becomes small, but when using my application for the first time it does not, that is, the keyboard does not normally affect the layout, but if I minimize the app and the I reopen the screen is reduced, I will show you an image.
First time open my app
After minimizing and reopening my application
I find the solution for this problem. Put the next code in the "OnCreate" of your app.
CODE:
getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_NOTHING);

Setting a specific image/view to be displayed in the recent apps list

I would like my app to show a "splash" screen in the recent apps list, but how can I do this?
I have tried to set that splash view as the first thin in onPause in my activity (and it is set, I can see it just before the app goes to the background), but still the screenshot Android takes of my app is what just before onPause is called. I have also looked into this method: onCreateThumbnail, but it is never called (it seems to be disabled).
What about the ActivityManager, can I somehow remove my app from the ActivityManager task list and add it again with addAppTask and give it a bitmap this way?
Thank you
Søren

Spinner inside custom ListView freezes on returning from another activity

Hello all here is my problem.
My app's listview (which is inside a tab widget) contains various types of rows. I have had many problems setting this up and here is another 1. Please see here for the code, which basically remains the same.
I use another activity (a custom implemented ES file explorer) which is a filebrowser dialog to open a file. The data from the file is sent to the listview.
When it shows the list and I click on the spinner the screen darkens and freezes. If I press the back button the darkening disappears, the listview becomes clickable but the spinner still is not. The only way out is if I flip to another tab widget and back again (there are 2 separate ones) the spinner will work again.
I should say that the spinner works just fine if I do not load files from the other activity.
So I guess in other words there is a problem of focus or something when switching and killing activities.
I hope you can help.
EDIT
after some more trying, sometimes after loading the file from the browser it will return to a black screen where the listview is there but not visible.
eg you can click on it and the editor opens.
Hi well again it took ages but here was the problem.
the custom listview had
this.setDescendantFocusability(FOCUS_BEFORE_DESCENDANTS);
set
so all I had to do was set
holder.techniquespinner.setDescendantFocusability(parent.FOCUS_BEFORE_DESCENDANTS);
for the spinner and voila; I haven't tried but it should probably go in the xml file.
Thanks to anybody who looked.
EDIT
Crap I spoke to soon. It still doesn't work.
There is 2 tabwidgets inside a flipper.
If returning from the browser to the tab where it left WITHOUT flipping the flipper it works.
Flip once, back again and then to the browser does not work.
I'm not even sure what code to post. It is quite complex.
FINAL EDIT
This is how I fixed it.
flipper.showNext();
and then back again.
It somehow refreshes the view brings it back to focus and useable again.
It isn't pretty but it works.

Android: Multiple ListViews in one Activity - only one will update graphics

have been sitting with this problem for a few days and really can't seem to find the answer myself.
I'm building an application for Android devices. The application will use a socket connection to a PC running a piece of software. The user have some buttons and stuff to change the state of the PC program - this part works well. Basicly by sending text to the PC using the socket.
I also want the Android application to handle incomming events from the PC. These events should alter the UI on the device in order to reflect the state of the PC program.
To understand my problem I will try to explain the structure of the app.
Basicly the app have four activities:
A splash activity, which shows a splash screen and after a set time launches the next Activity
A connector activity, which have an input where the user will type in the IP of the PC. When the device connects to the PC, the PC will send an xml file to the device basicly containing the state of the program. This xml file is parsed and when parsed without errors this activity launches the next Activity.
The next activity is a TabActivity, creating 1 to 5 tabs, depending on the xml that was parsed. Each tab needs an activity which will handle the content for each tab. Here I have chosen to use one activity for all tabs.
The last activity is the content activity. This is a ListActivity. When parsing the xml, items will be created and divided into 5 categories - one tab for each of these. When a tab is selected for the first time, the content will be generated, and a ListView object created for that tab. For each item in a category I inflate a layout (xml) and sets the correct graphics based on the state of the object. This works just fine. Switching between the tabs is fine aswell.
So - when switching tabs I check if the ListView for the tab is null, and if that is the case I will create the content, and if not then I will call the "setListAdapter(...)" with the correct "list.getAdapter()", where list will be the list related to the tab.
When receiving an event from the PC i have a Handler taking care of the event. This handler will parse the message, and find out what part of the UI to change, and what Object is related to this part of the UI. Then the state of the Object is changed to matter what - and if the obecjt's tab is currently open the View is changed aswell - if another View is opened a boolean will tell that an object in the tab has changed state.
I have tried to get the View from the ListView variable and change the child elements, but this do not work when the list is not the current list.
Then I tried to create a whole new ListView for the tab when the tab is getting pressed, if this boolean shows that something have been changed (just as it's created in the first place the first time) - this only works for one tab.
I've tried to test it with two of the tabs (2 and 3). The app starts on tab 1. If I then open tab 2 and then 3, sends commands to the PC from both tabs and all is fine. When the PC sends events to the app then only tab 3 will actually update. Working both when the tab is active and inactive (updates when getting active). While tab 2 does not update content on any changes.
If I only open tab 2 and not tab 3, then tab 2 will update in both cases just fine.
Anyone have any ideas to what can be done here?
I have tried all kinds of stuff with invalidate(), notifyDataSetChanged(), invalidateViews() etc, and nothing does the trick.
I really don't understand why, when creating a whole new ListView (from changed objects) that the old ListView will still be shown.
Did I shoot myself in the foot when choosing to use one activity for all tabs, or is this something else?
Hope someone can help me here.
And if some code is needed then please tell which part, as the app consist of ~15 classes and thousands of code lines, so I won't post it all :)
Cheers
I ended up with one activity for each tab content instead of the first approach where I had one Activity for them all and just switching between adapters for the listview when a tab was pressed.
Splitting it into an activity for each tab made it possible for all content to be changed no matter if the activity was showing or not.

Modifying application workflow to use TabActivity

This question actually has two parts.
The first part:
I've been developing my first app for a couple of weeks now. I have 5 screens and everything seems well. However, I'm considering changing the app's navigation to a TabView.
I haven't delved much into it, but I'm hoping someone can save me a little bit of time. It seems that people don't generally place Activities inside each tab. They simply point the tab content to a View. This is where my major setbacks are. 1) I already have Activity classes full of code and 2) I can't quickly guess how the structure of an app using TabView looks. For example, where do I put the handler code for clicking a button on a View? Does it all just get dumped into the TabView Activity somehow?
What I would like is if you could please give me a quick synopsis of what I'm looking at doing, answers to any questions you think I may have, and point me toward some resources for creating TabView applications. A quick Google search really just shows me how to create a TabView Activity and add a couple tabs to it. The code doesn't go any deeper. For example, say I have a layout xml to show in one of my tab's content pane, where does the code go for clicking a button I have in that layout?
The second part:
I've added a TabActivity to wrap the Activities I currently have in. At the moment I have Activities populating the content of my tabs (though ultimately I'd like to do this in the most efficient fashion, which doesn't seem to be having Activities be tab content). I've noticed something rather annoying. My MAIN Activity is an Activity I wrote for my user to log in to their account. After logging in, they are taken to my Tab Activity. Here is what happens:
When I am on my Tab Activity and I "minimize" the app by clicking the Home button and then launch it again, I don't get taken back to the Tab Activity. I get taken to my log in Activity. Why? I don't have the launchMode of my Tab Activity set to singleInstance... or is it singleInstance by default? How can I make the app re-launch showing the Tab Activity (ideally by setting some parameter, assuming I'm doing something wrong, and not having to save this data off somewhere and reading it and programmatically telling it what to go to)?
Thank you for all your time and help
I don't have a comment on the advisability avoiding the use of sub-activities in TabActivity. As for handlers -- if you aren't going to embed views instead of activities, then all the android:onclick type handler settings in your layout XML will call methods on the TabActivity. This is because they go to methods on the views' Context, which is the generally the nearest containing Activity. If you want to split your code up further without using Activities, I believe you'll have to use findViewById calls on the tab content views after you've set them up, and bind the handlers manually from there in your code.

Categories

Resources