SetContentView multiple times

Put your problem here if it does not fit any of the other categories.

SetContentView multiple times

Postby ebs2002 » Thu Feb 28, 2008 6:21 pm

This is a multi-part problem, so I apologize for the length.

I'm porting an application from PocketPC to Android. The PPC application has multiple windows that are displayed, and complex data structures are passed on to each of these windows.

The android way of doing this would be to create an activity for each view, but I haven't been able to find an easy way to send multiple classes through to android. I've tried serializing the data and passing it through a binary string, but this is too slow. I've tried creating an inflate/deflate method for my object (pulling out most member variables, passing them through to the next activity, then recreating the structure...basically my own serialization implementation), but that was also too slow.

Global Static class functions aren't really an option, because they aren't scalable (sometimes I have multiple instances of this data function).

SO, with all that background, my attempted solution was to call SetContentView multiple times. Each time I wanted to open a new window, I have a class that does everything OnCreate would do, just in a different function.

This worked great, actually. I was able to Open each window, it was fast, and the data was still shared.

The only problem is the back button. I can't seem to call SetContentView(R.layout.view1) if it was already called. I get a NullPointerException in Layout.onMeasure.

An example of what works:
setContentView(R.layout.view1);
// work with the data

setContentView(R.layout.view2); // when the user needs to open the next window
// work with the data
// ...

setContentView(R.layout.view3); // when the user needs to open the next window

However, if I change it to R.layout.view1 again, this crashes.

Is there a work-around to this? Or, is there a better way I can accomplish what I'm trying to do?
ebs2002
Once Poster
Once Poster
 
Posts: 1
Joined: Thu Feb 28, 2008 6:08 pm

Top

Return to Other Coding-Problems

Who is online

Users browsing this forum: Exabot [Bot] and 16 guests