Form1.Hide in VB .NET and SendToBack in B4A

bsnqt

Active Member
Licensed User
Longtime User
Dear All

Maybe it is one of the simplest questions and most stupid question I have as a newbie, but please help as I am really confused.

What is the function of Activity.SendToBack?
(And function of Activity.BringToFront?)

I attached here the simplest test project, as this function seems not working for me. When you click on the button (in the test project), nothing happens? or I did something wrong?

I am looking for something like Form1.Hide in VB .NET.

(I have read the other threads & topics like TwoPanelLayouts, TwoLayoutActivities, TwoPanelActivities, StartActivity(Main) etc. but still confused...)

With my best
bsnqt
 

Attachments

  • SendToBack.zip
    301.2 KB · Views: 165

Beja

Expert
Licensed User
Longtime User
Make sure you have the following line in Sub Globals:

Dim Button1 As Button, so it can look like:

B4X:
 Sub Globals
   'These global variables will be redeclared each time the activity is created.
   'These variables can only be accessed from this module.

   Dim Button1 As Button
End Sub
 
Upvote 0

bsnqt

Active Member
Licensed User
Longtime User
Have you looked at: Basic4android - Views (Core) ?

You may also might be looking at finishing the Activity by using Activity.Finish which will close the Activity

Thank you for your answer and help.

Yes Sir, I did look on the link you advise...sure.

You are correct, we need to use Activity.Finish but it cause the Activity to Close and then when we want to bring it back to the front, I need to re-initialize. So if on my main Activity I have some codes to run then it will take time to re-initialize.

Best

bsnqt
 
Upvote 0

bsnqt

Active Member
Licensed User
Longtime User
Make sure you have the following line in Sub Globals:

Dim Button1 As Button, so it can look like:

B4X:
 Sub Globals
   'These global variables will be redeclared each time the activity is created.
   'These variables can only be accessed from this module.

   Dim Button1 As Button
End Sub

Beja,

Thanks for your answer. But what do you mean?

(I did put the declaration for Button1 in the Sub Globals, please check my test project).

Best

bsnqt
 
Upvote 0

DouglasNYoung

Active Member
Licensed User
Longtime User
bsnqt,
I think you need to get your head round 'Android activities & lifecycles' check out the Documentation tab above. When switching activities the OS decides when (or not) to close the background activity, therefore you need to use the Activity_Pause and Activity_Resume events to preserve/recreate the activity state. There is also a library to help with this....
 
Upvote 0

IanMc

Well-Known Member
Licensed User
Longtime User
This acts like the user pressed the home button on their device:

B4X:
Sub ShowHomeScreen 'programmatically press the Home button on the Android device
   Dim i As Intent    
   i.Initialize(i.ACTION_MAIN, "")    
   i.AddCategory("android.intent.category.HOME")    
   i.Flags = 268435456    
   StartActivity(i)
End Sub
(I think this is Erel's code)
So if in your code you do
ShowHomeScreen
then your application will disappear into the background.
If you have a piece of code in your application that can then later do something like:
StartActivity("main")
(or any other of your activities)
Then your app will magically appear again.

It is true that while your app is sitting in the background the system might decide to trash it, there are ways around this.

In my app I have a service, when I do ShowHomeScreen it zooms off into the background but its still working! I can get it to play sounds, TTS speach, Toast pop up messages etc. Then bring it back to the foreground again at will.

One more thing, that ShowHomeScreen sub really does act like someone pressed the home key, try pressing the home key several times on your device to see what I mean.
 
Upvote 0

bsnqt

Active Member
Licensed User
Longtime User
@ IanMc and DouglasNYoung:

Thanks for your advice on this. Yes I will look into many possible ways / options to get the best for my case.

What I also meant is that for Android it seems more complicated - at least for me - to get similar function like Form1.Hide (in Net) as you have to decide which way you have to go, depending on the specific situation / project. But positively speaking, it gives me more challenges to overcome (and learn) and more interesting ways to discover.

In my project I have to use Activity.Finish and also take care of the Activity_Pause Sub. I will test it for a while, I may also have to use ShowHomeScreen like DouglasNYoung suggested.

Thanks again Sirs ;)

Best

bsnqt
 
Last edited:
Upvote 0

mangojack

Expert
Licensed User
Longtime User
Thinking we might be mis-reading bsnqt 's question ,I played around with 2 activities for the first time. I understand how you can use .ToFront and .toBack with views ect .. but now find me asking to same ..

What is the function of Activity.SendToBack?
(And function of Activity.BringToFront?)

It was going to happen anyway ...

Cheers mj
 
Upvote 0

bsnqt

Active Member
Licensed User
Longtime User
In my app I have a service, when I do ShowHomeScreen it zooms off into the background but its still working! I can get it to play sounds, TTS speach, Toast pop up messages etc. Then bring it back to the foreground again at will.

In the case that the app has no service (or has a service but it does not have notification in the notificiation bar), how we keep it not to be killed by the Android OS?

I remember I read somewhere (maybe from Erel) the way how to do that, but cannot recall or may not be updated.

EDIT. I will test it for a while, I may also have to use ShowHomeScreen like IanMc suggested.

Thank you!

bsnqt
 
Last edited:
Upvote 0

bsnqt

Active Member
Licensed User
Longtime User
@IanMc:

In the opposite, I believe there should not be always to have the notification in the notification bar...you can find many of such application in Google Market... I even use different Task Managers to kill them but not always you can succeed in killing them, or you can kill but they can restart itself immediately :(

Best

bsnqt

EDIT. I will test it for a while, I may also have to use ShowHomeScreen like IanMc suggested. SORRY SIR :D
 
Last edited:
Upvote 0
Top