Android Question AddReplacement(android.intent.action.MAIN, unused_action) doesn't work

Alessandra Pellegri

Active Member
Licensed User
Longtime User
This is the code in the Main:
B4X:
#Region  Project Attributes
   #ApplicationLabel: B4A Example
   #VersionCode: 1
   #VersionName:
   'SupportedOrientations possible values: unspecified, landscape or portrait.
   #SupportedOrientations: unspecified
   #CanInstallToExternalStorage: False
#End Region

#Region  Activity Attributes
   #FullScreen: False
   #IncludeTitle: True
#End Region

Sub Process_Globals
   'These global variables will be declared once when the application starts.
   'These variables can be accessed from all modules.

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:
   Log("OK_1")
   StartService(Trova)
   Activity.Finish
   'Activity.LoadLayout("Main")

End Sub

Sub Activity_Resume

End Sub

Sub Activity_Pause (UserClosed As Boolean)

End Sub

If I put in the manifest AddReplacement(android.intent.action.MAIN, unused_action) the code simply doesn't start. (Or so I think because I can't see OK_1 in the log).

If I remove AddReplacement(android.intent.action.MAIN, unused_action) from the manifest, everything works perfectly but I see an empty activity when I press the button of the tasks.

Where do you think that my mistake is ?

Thank you
 

DonManfred

Expert
Licensed User
Longtime User
Where do you think that my mistake is ?
You are mnot loading a Layout in the activity.
Sub Activity_Create(FirstTime As Boolean)
'Do not forget to load the layout file created with the visual designer. For example:
Log("OK_1")
StartService(Trova)
Activity.Finish
'Activity.LoadLayout("Main")

End Sub
You should move the Activity.finish to a sub and call that sub with callsubdelayed from activity_create.
 
Upvote 0

Alessandra Pellegri

Active Member
Licensed User
Longtime User
Ok, now my code is this:
B4X:
#Region  Project Attributes
   #ApplicationLabel: B4A Example
   #VersionCode: 1
   #VersionName:
   'SupportedOrientations possible values: unspecified, landscape or portrait.
   #SupportedOrientations: unspecified
   #CanInstallToExternalStorage: False
#End Region

#Region  Activity Attributes
   #FullScreen: False
   #IncludeTitle: True
#End Region

Sub Process_Globals
   'These global variables will be declared once when the application starts.
   'These variables can be accessed from all modules.

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:
   Log("OK_1")
   Activity.LoadLayout("Main")
   CallSubDelayed(Activity,"CloseActivity")
   StartService(Trova)
End Sub

Sub CloseActivity
   Activity.Finish  
End Sub

Sub Activity_Resume

End Sub

Sub Activity_Pause (UserClosed As Boolean)

End Sub

But all that I can see in the log is this :


If it is necessary I attach all my project. It is just an experiment
 
Upvote 0

Alessandra Pellegri

Active Member
Licensed User
Longtime User
I have changed
CallSubDelayed(Activity,"CloseActivity")
to
CallSubDelayed("Main","CloseActivity")

(Tried also CallSubDelayed("","CloseActivity") )

But the problem persists.
 
Last edited:
Upvote 0

Alessandra Pellegri

Active Member
Licensed User
Longtime User
I bought a Chipolo ( https://chipolo.net/ ).
But I am very unsatisfied about the original app. It very often fails and doesn't notify me the "out of range".

So I am triyng to write mine. I saw that the chipolo continuosly radiates its MAC address via bluetooth.
So my idea is to periodically test if the mac address is in range.
So I wrote the attached code.

It should stay in background and alert me when the Chipolo is out of range. It works if I use the Activity and if I keep my phone alive.
But it should work when the phone is in my pocket.

Thank you
 

Attachments

  • TestProject.zip
    47.6 KB · Views: 230
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…