run app without showing layout

noclass1980

Active Member
Licensed User
Longtime User
Hi, I have a very simple app to toggle the bluetooth off/on depending on its current state and then closes the app using ExitApplication. However, the screen flashes black while running because there is no defined layout. How can I run the app from my Galaxy tab home screen without the screen changing so the user (me!) doesn't know its run other than the toast message that appears? Long question, hopefully short answer! any suggestions? Thanks
 

warwound

Expert
Licensed User
Longtime User
There is a built in android theme that might be useful here.
I've seen it used in some android (not b4a) source code, the activity runs invisibly.

This is the code i've seen in an eclipse project manifest file:

B4X:
        <activity
            android:name=".StandOutExampleActivity"
            android:excludeFromRecents="true"
            android:label="@string/app_name"
            android:theme="@android:style/Theme.NoDisplay" >
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>

I tried various ways to add this to a b4a manifest and it didnt work, the app failed to start if i remember correctly.

But in theory it can be used with the correct manifest syntax, android:theme="@android:style/Theme.NoDisplay" is obviously the line to add.

Martin.
 
Upvote 0

noclass1980

Active Member
Licensed User
Longtime User
Still not working

It should be:
B4X:
SetActivityAttribute(main, android:theme, "@android:style/Theme.NoDisplay")

Unfortunately, this did not work. When I press the app icon, the screen flashes black and then returns to home screen. Not really an issue but what I'd really like is for the home screen to stay visible and a popup message saying Bluetooth enabled/disabled as appropriate. I've tried toastmessage, ProgressDialog and notifications but none work the way I want. I also tried a Service module as Erel suggested which worked as long as the ProgressDialog lines were removed (produced a error message about not being able to open window). If I step through the code with F8 then then toastmessage appears. Any suggestions? Thanks. Code is below

B4X:
Sub Process_Globals
   'These global variables will be declared once when the application starts.
   'These variables can be accessed from all modules.
Dim bTadmin As BluetoothAdmin
End Sub

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

End Sub

Sub Activity_Create(FirstTime As Boolean)
   'Do not forget to load the layout file created with the visual designer. For example:
   'Activity.LoadLayout("Layout1")
bTadmin.Initialize("")
Check_State
'StartService(BTStatusCheck)

End Sub

Sub Activity_Resume
'bTadmin.Initialize("")
End Sub

Sub Activity_Pause (UserClosed As Boolean)

End Sub
Sub Check_State
Dim Now As Long
If bTadmin.IsEnabled=True Then 
'ProgressDialogShow("Disabling BlueTooth, please wait")
ToastMessageShow("Bluetooth disabled",True)
bTadmin.Disable
'ProgressDialogHide
Else 
'ProgressDialogShow("Enabling BlueTooth, please wait")
ToastMessageShow("Bluetooth enabled",True)
bTadmin.Enable
'ProgressDialogHide
End If
ExitApplication
'Activity.Finish
End Sub
 
Upvote 0

noclass1980

Active Member
Licensed User
Longtime User
will try

Your best option is to use a widget (and a service).

Note that ExitApplication is not needed and will only cause problems in this case.

Ok, I'll try that. Not used widgets before but does the service send information to the widget? I'll look at the forum for a tutorial unlesss you can suggest one. Thanks
 
Upvote 0

noclass1980

Active Member
Licensed User
Longtime User
widget not showing

Ok, I'll try that. Not used widgets before but does the service send information to the widget? I'll look at the forum for a tutorial unlesss you can suggest one. Thanks

Hi, I found your Homewidget tutorial, installed it and it works as it should. I then tried to create my own based on the WidgetService module and it compiles ok but the widget isn't showing in the widget list like the Homewidget did. The code is the same but my layout is different. I've made sure that the imageview and label are childs of the Panel. Any suggestions as I cannot see what the difference is. The app runs ok in that it shows the message in the Activity_Create sub but the widget doesn't make it to the list. Thanks
 
Last edited:
Upvote 0

noclass1980

Active Member
Licensed User
Longtime User
Can you upload your project (File - Export as zip)?

The zip file is added. As you will see I've commented out the bluetooth enable/disable lines for testing purposes only. The issue is that when I install the app the widget is not appearing in the widget list as the Homewidget did without any problem. Thanks in advance
 

Attachments

  • BTtoggle2.zip
    85.8 KB · Views: 225
Upvote 0

noclass1980

Active Member
Licensed User
Longtime User
Why did you check: "Do not overwrite manifest file"? This is causing this problem.

I really have no idea how that happened.
Will test it later but thank you very much in advance. Much appreciated.
 
Upvote 0

noclass1980

Active Member
Licensed User
Longtime User
I really have no idea how that happened.
Will test it later but thank you very much in advance. Much appreciated.

Hi, thank you now works like a dream, just how I wanted it. Have been using B4A for a couple of months now and loving it more every day. Great tool for developing apps.
:sign0060:
 
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…