Android Tutorial Two activities example

gkumar

Active Member
Licensed User
Longtime User
Process_global variable will not hold data when we switch to another activity

I have string declared in Process_Globals of main activity. When I switch to another activity, the variable is not holding the data. I want this variable to be hold the data for another activity. How to overcome this problem?
 

gkumar

Active Member
Licensed User
Longtime User
Process_Global variable not holds the value

Declaring the variable in the Process_Globals of Main activity as
Dim gStrToken As String

In the Parser_EndElement method assigning the value as,
gStrToken = Text.ToString.Trim (Verified that value has been copied)

And in the Activity_Create of another activity accessing the value as,
Main.gStrToken
where the value is empty.

Whts wrong here?
But in another way, I added a New code module to store this value, it works fine for me. Let me know whether anything is missing here.
 

Kevin

Well-Known Member
Licensed User
Longtime User
I've been having similar issues lately as well.

I have a list object (not listview) in my main activity. The user can start a second activity and that activity reads in the data from the list in the main activity (the list is a process global in the main activity). This data is read each time the second activity starts and is used to populate a listview.

This normally all works well. However, in the second activity the user can press a button that opens a web page in the device's default browser. If the device gets low on memory while the second (and first) activity is paused while the user is in the browser, then Android seems to be killing the first activity (and possibly the second).

My problem then arises when the user backs out of the browser and the OS returns to my second activity. At that point I get an error when the second activity tries to populate the listview with the first activity's list data saying that the list in the first activity is not initialized.

Since the source list is in the first activity and I can do nothing about it, the only solution I have come up with is to kill the second activity (ExitApplication) if a check of whether or not the list in the first activity is initialized comes back as false. This then kills the second activity before it ever really shows again and sends the user back to the first activity (and I assume it is then recreated).


I think part of the issue is with my phone. I have an EVO 4G and over the past few updates to it they have cracked down on killing background processes. As a result, background processes tend to get killed way too often. The biggest problem with the EVO 4G now is that they got so agressive with it that the "Sense" parts of the phone (basically HTC's custom interface and widgets) get killed way too often.

It's so bad that if I use the EVO's built in RSS widget and open a story in the default browser then I can almost always kill the Sense process on demand simply by doing an everyday thing such as reading a few news articles. Sometimes the phone even kills the browser while I am reading a story and dumps me back to the RSS widget app. To add insult to injury, many times when I get dumped back to the RSS widget (or just return to it after reading a story) the widget is empty and says there are no stories even though there were 100 stories before I tried to read the article. This is of course because the widget itself is getting killed and recreated.

On the plus side, it makes it easy for me to see what happens when my app gets killed by the OS. All I need to do is press Home, read a couple articles and wait for the phone's interface to completely restart then return to my app.
 

Kevin

Well-Known Member
Licensed User
Longtime User
Sounds like that would probably work! I should have thought of that myself.

I'm working long hours the next few days but when I get a chance I wil try this.

Thanks!

What are the chances of Android killing a code module while my activity or activities are paused?
 

Kevin

Well-Known Member
Licensed User
Longtime User
I had some time to test this today and I guess my phone must be killing the whole process.

I had moved the list from main to the code module. In the second activity I create a new list based on information found in the other list (now in code module). When I forced my phone to kill off its processes and then returned to my app, neither list was still initialized. Both the list in second activity and the original list now Dim'd in the code module came back as not initialized. I tried initializing the original list in the code module but then I once got an error in my main activity where it said the list was not initialized.

Oh well. I guess I'll just have to leave it how I had it, where the second activity checks to see if the lists are no longer initialized and if not, just kill the second activity through code. It's not perfect but it sure beats an empty page or an error that a list is not initialized.
 

gkumar

Active Member
Licensed User
Longtime User
Process_Global variables not holding the value

Still application is not holding the Process_Globals variable values. Any other settings missing?
 

Kevin

Well-Known Member
Licensed User
Longtime User
Yes, I think that is just about my only option. More work again, when I was hoping to be ready to push an update, but it will be better for it. I'd probably end up doing it at some point anyway.
 

sioconcept

Active Member
Licensed User
Longtime User
Hi all,

I've the same problem. I've 2 activity; when i start the second activity, the first activity is destroyed, so when i back again on the first i lost all data. How i can switch without lost data ? The data is some texts, panels, labels etc.. so i can't save it directly.

Have you find a solution ?
 

ADPTraining

Member
Licensed User
Longtime User
Too many panels is not a good idea...

Just for the record... I've been working on an APP and have added up to 8 panels(.bal) with many views. At one point the software decided not to make any more views. So, I removed one panel with it's dedicated views and it all started working again. I did not get any errors, just that the lastly created views did not show or only the Button text would show.

I ran into this issue years ago with Visual Basic in putting too much stuff into one form. I knew it would happen here sooner or later. So, the best and only programming practice (if your APP has lots of views/controls) is to divide into separate Activities and call them as needed. For large APPs Activity calling is the only way.
 

Noize

Member
Licensed User
Longtime User
What is the difference between Activity.Loadlayout and StartActivity?

Tnx
 
Cookies are required to use this site. You must accept them to continue using the site. Learn more…