Android Question How to prevent application excution when rotate device

ttsolution

Member
Licensed User
Longtime User
Dear all,
I have question as follow

Sub Activity_Create(FirstTime As Boolean)
Activity.LoadLayout("MyReport")
LoadReport ' this sub get data from webservice and display result in ListView
End Sub

The problem is when I rotate the device, the sub LoadReport is called again automatically (take time). I suppose it is no need because all data is available in screen already (just rotate layout)

Please advice me how to solve this

Many thanks,

Jonh,
 

eps

Expert
Licensed User
Longtime User
As Erel has already stated, you need to only execute that code when FirstTime is True. You need to be aware of the activity lifecycle, which Erel has given you a link to, which I was going to recommend reading as well, when I first read your OP.

In addition to this, either you need to store and restore the information (if stored in local variables) or store them in global variables, which goes against traditional programming practice, but works well for Android Apps. Not only will the information be readily available, it should also use less memory for the lifecycle of the device, as it's only defined and used once, as opposed to many times. Quite often re-defining variables seems to use up more and more memory as the garbage collector struggles to keep up with the definition and use of those variables.
 
Upvote 0

ttsolution

Member
Licensed User
Longtime User
Dear Experts,

My Activity have just have one WebView. In Activity_Create I call a web service to load a webpage to this WebView.
Every time I rotate the device, if I do not call webservice again the WebView will be empty, if call again it takes time. As your recommendation I need to store my result to a local variable and re-display to user, but I do not known how to save a web page to variable.

Regards,

Jonh,
 
Upvote 0
Top