Caching Current View of the activity

Put problem concerning Views, Layouts and other XML-Resources (like AndroidManifest) here.

Caching Current View of the activity

Postby tamojit_sengupta » Tue Nov 24, 2009 10:05 am

Hi,

My application has some good number of screens and i am using a single activity to display them all by calling setContentView method. I have given specific implementation to the back key to go the previous layout. My problem is i am not able to cache a view which i can directly take and display. I have to recreate the screen altogether.

Is there a way to cache the current view in the activity and then display it again by some way.

thanks in advance.

Tamojit
tamojit_sengupta
Freshman
Freshman
 
Posts: 2
Joined: Tue Nov 24, 2009 9:22 am

Top

Postby divestoclimb » Tue Nov 24, 2009 7:30 pm

I'm not sure why you're trying to do that, but here's one way...
  • Call setContentView once, on a XML file that contains only an empty FrameLayout
  • Based on which view you want to show, inflate the view using a LayoutInflater into the FrameLayout. Change the visibility of all sibling Views so they are invisible. Keep track within your Activity of which Views have been inflated.
  • If you want to switch to a View that's already been inflated, just change its visibility instead of re-inflating it.
I would recommend that you rethink why you're doing this. I don't know anything about the rest of your design goals, but that sort of thing sounds like it would be easier to do by handling each screen as a separate Activity.
divestoclimb - Android SCUBA app developer
Android Community | Gas Mixer, ScubaLib, Scuba Tanks | d2c Checklist
All code is open source under Apache license.
divestoclimb
Developer
Developer
 
Posts: 33
Joined: Mon May 11, 2009 7:46 pm

Postby tamojit_sengupta » Wed Nov 25, 2009 6:45 am

Hi,

thanks for the reply. I understand that the right way to do it is having different activities and thats the way it was designed initially. But there seems to be some limitation of the emulator to have many activities simultaeously and used to throw SurfaceManager out of memory and used to crash.
I have raised this issue in the google forums with no luck.

http://code.google.com/p/android/issues ... ry%20Stars

let me know if u have any idea on this.
tamojit_sengupta
Freshman
Freshman
 
Posts: 2
Joined: Tue Nov 24, 2009 9:22 am

Top

Return to View, Layout & Resource Problems

Who is online

Users browsing this forum: No registered users and 7 guests