Hiding an activity

derez

Expert
Licensed User
Longtime User
How can I make an activity not seen ?
I want to use the camera (which to my understanding cannot be run from a service) but without showing the activity.
What I have now is a black screen, how can this be eliminated ?
 

derez

Expert
Licensed User
Longtime User
Erel. thank you. I need some more advice here, as this solution is only "half working" :

I have two activities, one should be visible when active, the other- hidden.

The manifest is common to all the activities and I need this transparency only in one of them. In the manifest I changed from main to "camera" (the other activity) and I get (on the emulator) white background for the main activity and top half black screen on the camera activity.

Maybe it is only on the emulator, I'll check later on a device.
 
Last edited:
Upvote 0

derez

Expert
Licensed User
Longtime User
Found the answers to the above -
The half screen was the camera panel (which is not transparent).
To inhibit the transparency of the main activity I add a panel under all views so it is shown normally.

Edit:
The camera will not take a picture if the panel used by the camera is not visible ( either visible = false or out of the active screen area) but it works if the panel is partially visible, even if partially is one pixel !!!
So I put the panel in left = Activity.Width - 1, top = Activity.Height - 1 . This way the activity is transparent, the panel hides only one pixel.
 
Last edited:
Upvote 0

SpinBower

Member
Licensed User
Longtime User
Found the answers to the above -
The half screen was the camera panel (which is not transparent).
To inhibit the transparency of the main activity I add a panel under all views so it is shown normally.

Edit:
The camera will not take a picture if the panel used by the camera is not visible ( either visible = false or out of the active screen area) but it works if the panel is partially visible, even if partially is one pixel !!!
So I put the panel in left = Activity.Width - 1, top = Activity.Height - 1 . This way the activity is transparent, the panel hides only one pixel.
Hi could you post your code for the solution?
 
Upvote 0

derez

Expert
Licensed User
Longtime User
could you post your code for the solution?
B4X:
Sub Activity_Create(FirstTime As Boolean)
Activity.Color = Colors.Transparent
photopanel.Initialize("")
Activity.AddView(photopanel,Activity.Width - 1dip,Activity.Height - 1dip,480,480)'ignore
End Sub
 
Upvote 0

SpinBower

Member
Licensed User
Longtime User
B4X:
Sub Activity_Create(FirstTime As Boolean)
Activity.Color = Colors.Transparent
photopanel.Initialize("")
Activity.AddView(photopanel,Activity.Width - 1dip,Activity.Height - 1dip,480,480)'ignore
End Sub

Sorry but could you post an example b4a project that takes a picture from service as you described?
 
Last edited:
Upvote 0

derez

Expert
Licensed User
Longtime User
Sorry but could you post an example b4a project that takes a picture from service as you described?
I have not mentioned that my application uses a service to take the picture. Actually it is impossible, like Erel said in this link :
http://www.b4x.com/android/forum/threads/take-a-picture-from-a-service.39075/
The solution describes the way to use an activity but not show the picture while taking it. My application takes a picture in the front camera and sends it to my email (with position from GPS and address) every few seconds - for the case the phone is lost or stolen...
 
Upvote 0

SpinBower

Member
Licensed User
Longtime User
I have not mentioned that my application uses a service to take the picture. Actually it is impossible, see this link :
http://www.b4x.com/android/forum/threads/take-a-picture-from-a-service.39075/
The solution describes the way to use an activity but not show the picture while taking it. My application takes picture in the front camera and sends it to my email (with position from GPS and address) every few seconds - for the case the phone is lost or stolen...
Yes, my app is a security app. I need it for the same reason you do!
 
Upvote 0

Gentry

Member
Licensed User
Longtime User
Is there a way to control the screen/activity that is displayed behind a translucent app like this? I create a notification so that a user could jump from a specific app (a game) to my translucent app, however behind the translucent app the home screen is always displayed, rather than the screen from the app that was displayed prior to using the notification to jump to my translucent app.

Thanks for consideration.
 
Upvote 0

Gentry

Member
Licensed User
Longtime User
Thanks for the quick response.

I created a Object/res/values/styles.xml file and pasted in the example from Stackoverflow, modified the project manifest to use the @style/Theme.Transparent (both as a Activity and Application Attribute), which has an effect on the application, it now displays one large white box instead of the controls that the application is supposed to display. First time with a custom style, not sure if there is more to it than what I have done.

Still I can tell on the border, that the background behind this area is the home screen, not the game I am trying to display in the background of my translucent application. It seems that when the notification is activated, that the screen stack navigates from the game, to the home screen, then the translucent application is rendered (showing the home screen behind my app).

Is there a way for my application to reverse the screen stack so that before the translucent app renders, the screen before the home screen is rendered, to achieve this goal?

Again, thank you.
Gentry
 
Upvote 0

xor83

Member
Licensed User
Longtime User
I added this for activity:
SetApplicationAttribute(android:theme, "@style/MyAppTheme")
SetActivityAttribute(AddUserForm, android:theme, @android:style/Theme.Translucent.NoTitleBar)

It show as popup but the controls (Look and feel) is not similar to main activity, how can I tell this Translucent activity to use same theme as Main activity?
 
Upvote 0

Erel

B4X founder
Staff member
Licensed User
Longtime User
Use this manifest editor code (requires B4A v5.80+):
B4X:
SetActivityAttribute(Main, android:theme, @style/CustomActTheme)
CreateResource(values, theme.xml,
<resources>
  <style name="CustomActTheme" parent="@android:style/Theme.Holo">
  <item name="android:windowIsTranslucent">true</item>
  <item name="android:windowBackground">@android:color/transparent</item>
  <item name="android:windowContentOverlay">@null</item>
  <item name="android:windowNoTitle">true</item>
  <item name="android:backgroundDimEnabled">true</item>
  <item name="android:windowFullscreen">true</item>
</style>
</resources>
)

http://stackoverflow.com/questions/12858733/translucent-dialog-theme-for-holo
 
Upvote 0
Top